Drawing directly with QPainter and drawing QPixmap give different results
Unsolved
QML and Qt Quick
-
There's a simple class based on
QQuickPaintedItem
:class PaintedItem : public QQuickPaintedItem { Q_OBJECT public: PaintedItem(); void paint(QPainter *painter) override; }; // ... PaintedItem::PaintedItem() { setRenderTarget(QQuickPaintedItem::FramebufferObject); } void PaintedItem::paint(QPainter *painter) { painter->drawRect(0, 0, 150, 150); QPixmap* m_pixmap = new QPixmap(width(), height()); m_pixmap->fill(QColor("transparent")); QPainter painter2(m_pixmap); painter2.setPen(QColor("red")); painter2.drawRect(0, 0, 150, 150); painter->drawPixmap(0, 0, *m_pixmap); }
The
paint()
function just does two things: draw a rectangle directly withQPainter
and draw theQPixmap
containing the same rectangle. But if I set the render target asFramebufferObject
in the constructor, those rectangles doesn't match for some reason. If I comment this string, everything's OK.With
FramebufferObject
WithoutFramebufferObject
Could you please explain me why does it happen and how to deal with it?