我创建了一个QPixmap,并使用QPainter在其上绘制了较小的QPixmap。我想用图像作为QQuickItem的背景。有什么简单的方法吗?
发布于 2015-08-23 03:22:54
如果您的自定义项派生自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;
}注意:您的项目是QSGTexture *texture__的所有者,不要忘记在销毁对象时删除它。
https://stackoverflow.com/questions/32162215
复制相似问题