gpt4 book ai didi

qt - 向 QQuickItem 添加背景图像

转载 作者:行者123 更新时间:2023-12-02 00:58:10 25 4
gpt4 key购买 nike

我创建了一个 QPixmap 并使用 QPainter 在其上绘制了较小的 QPixmap。我想将图像用作 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;
}

注意:你的元素是QSGTexture *texture的所有者,不要忘记在对象销毁时删除它。

关于qt - 向 QQuickItem 添加背景图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32162215/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com