C++ 对多个QGraphics站点共享相同的QGraphicsEffect 我所做的:
我正在视图(QMainWindow)的构造函数中创建一个新的QGraphicsEffect: 然后我创建了几个QGraphics站点:C++ 对多个QGraphics站点共享相同的QGraphicsEffect 我所做的:,c++,qt,opengl,reference,qgraphicsitem,C++,Qt,Opengl,Reference,Qgraphicsitem,我正在视图(QMainWindow)的构造函数中创建一个新的QGraphicsEffect: 然后我创建了几个QGraphics站点: QGraphicsItem *item = new QGraphicsItem; item->setGraphicsEffect(m_blurEffect); //<< This Line is where I need help m_scene->addItem(item); 在视图中(从中获取指向效果的指针) 它的作用是: 在创建
QGraphicsItem *item = new QGraphicsItem;
item->setGraphicsEffect(m_blurEffect); //<< This Line is where I need help
m_scene->addItem(item);
在视图中(从中获取指向效果的指针)
它的作用是: 在创建进度之后,似乎只有其中一项包含指针。 在创建新的QGraphicsItem后,我使用qDebug向我显示指向m_blurEffect的指针是否正确
for(...)
{
QGraphicsItem *item= new TileGraphicsItem();
item->setGraphicsEffect(m_blurEffect);
qDebug() << m_blurEffect << tileItem->graphicsEffect();
}
除了创建的最后一个项目外,它还包含正确的引用(在我的例子中是QGraphicsBlerEffect(0x139ce140))
那我该怎么办? 我想实现的是,它们都共享对一个QGraphicsEffect*对象的正确引用,这个对象是我在它们存在之前创建的
如有必要,我可以提供更多详细信息。
QGraphicsEffect
s不能在多个图形项目之间共享。您需要为每个图形项目创建图形效果对象。请参阅QGraphicsItem::setGraphicsEffect的文档:
如果效果安装在不同的项目上,setGraphicsEffect()将从该项目中删除效果并将其安装在此项目上。QGraphicsItem拥有效果的所有权
QGraphicsEffect
s不能在多个图形项目之间共享。您需要为每个图形项目创建图形效果对象。请参阅QGraphicsItem::setGraphicsEffect
的文档:
如果效果安装在不同的项目上,setGraphicsEffect()将从该项目中删除效果并将其安装在此项目上。QGraphicsItem拥有效果的所有权
m_blurEffect->setEnabled(false); //(true)
for(...)
{
QGraphicsItem *item= new TileGraphicsItem();
item->setGraphicsEffect(m_blurEffect);
qDebug() << m_blurEffect << tileItem->graphicsEffect();
}
qDebug() << graphicsEffect();
QObject(0x0)