1

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?

General Gravicius
  • 181
  • 1
  • 2
  • 10

2 Answers2

1

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

General Gravicius
  • 181
  • 1
  • 2
  • 10
0

If you are willing to use SVGs, here's a way to do it: In your .pro-File: QT += core gui svg

header

#include <QtSvg>

class Board: public QGraphicsItem{

    public:

        Board();      
       ~Board();

        QRectF boundingRect() const override;
        void paint(QPainter *painter,
             const QStyleOptionGraphicsItem *option,
             QWidget *widget = nullptr) override;

        QGraphicsSvgItem *item;


};

cpp

Board::Board(){

    item = new QGraphicsSvgItem("folder/icon.svg");
    item->setParentItem(this);
    item-> ... /// set Pos() and so on here

}

You can set Antialiasing in your QGraphicsView as well, then all items will take the effect: QGraphicsView::setRenderHint(QPainter::Antialiasing)

HL94
  • 41
  • 3