(Qt C ++) Resizing pixmap and KEEP pixelation?

In my project, I have QLabel that I often change pixmap as follows:

ui->frameLabel->setPixmap(slot_pic[blockId[currentSlot]][damageId[currentSlot]]); 

slot_pic is just a 2d card. So you can look at it more clearly:

 ui->frameLabel->setPixmap(pixmap); 

The image is 16x16 and my label is 32x32. My scaledContents are checked, so when changing the pixmap, the image has a double size. However, the image is now blurry. I understand why, but I was wondering if there was a way to make him stay uneven. I want to just enlarge the image in pixels. (Image from Minecraft, if that helps you understand what I mean)

Thank you for your time:)

+6
source share
1 answer

Do not let QLabel do the scaling. Instead, do the scaling yourself using QPixmap::scaled() . Something like that:

 ui->frameLabel->setPixmap( pixmap.scaled(32, 32, Qt::IgnoreAspectRatio, Qt::FastTransformation)); 

An important parameter is the latter, transformMode , which indicates whether bilinear filtering is used.

+15
source

Source: https://habr.com/ru/post/949628/


All Articles