有一个简单的类基于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);
}
该paint()
函数只做两件事:直接绘制一个矩形QPainter
并绘制QPixmap
包含相同矩形的矩形。但是如果我在构造函数中设置渲染目标FramebufferObject
,这些矩形由于某种原因不匹配。如果我评论这个字符串,一切都很好。
和 FramebufferObject
没有 FramebufferObject
您能解释一下为什么会发生这种情况以及如何处理吗?