Adding a background image to a QQuickItem
1 answer
If your custom element derived from QQuickItem
you can override QQuickItem::updatePaintNode()
, perhaps this way:
QSGNode *MyItem::updatePaintNode(QSGNode *oldNode, QQuickItem::UpdatePaintNodeData *)
{
QSGSimpleTextureNode *node = static_cast<QSGSimpleTextureNode *>(oldNode);
if (!node) {
node = new QSGSimpleTextureNode();
QSGTexture *texture = window()->createTextureFromImage(m_pixmap.toImage());
node->setTexture(texture);
}
node->setRect(boundingRect());
return node;
}
Please note: your item is the owner QSGTexture *texture
, remember to delete it when you destroy the item.
+5
source to share