我用它创建了一个QPixmap
并绘制了较小的QPixmap
s QPainter
.我想用图像作为背景QQuickItem
.是否有捷径可寻?
如果您的自定义项目QQuickItem
可以通过QQuickItem::updatePaintNode()
以下方式重新定义:
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;
}
Run Code Online (Sandbox Code Playgroud)
注意:你的物品是物主QSGTexture *texture
,不要忘记在物体破坏时删除它.
归档时间: |
|
查看次数: |
1633 次 |
最近记录: |