General Gravicius
General Gravicius

Reputation: 301

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):

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

Upvotes: 2

Views: 1033

Answers (2)

General Gravicius
General Gravicius

Reputation: 301

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

Upvotes: 1

HL94
HL94

Reputation: 51

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)

Upvotes: 0

Related Questions