Search code examples
qtpixelqpainterqimageqpixmap

Qt Graphics: the painting of a QImage is very pixelated


I'm drawing my game's board using QPainter and QImage but it's very pixelated and I don't understand why.

Pixelated board:

Game board

Actual pictures used:

Actual pics

Code:

Loading of the picture part:

QImage desert_pic = QImage(":/images/graphics/pi.png");
c_mapicons.insert({type, desert_pic});  

Painting part:

QRectF source(0.0, 0.0, 500.0, 500.0);
painter->drawImage(boundingRect(), c_mapicons.at(m_gameobject->getType()), source);  

The pictures are 500x500 png files. What I've tried (with no success):

  • Using svg files
  • Using QPixmap instead of QImage
  • QPainter::RenderHint(QPainter::Antialiasing)
  • QPainter::RenderHint(QPainter::SmoothPixmapTransform)

How can I get my pictures to appear smooth like in the second screenshot?


Solution

  • I managed to solve the problem by resizing to the size of my tiles before painting. More details here: Qt resize image with best quality