[英]stop event propagation from QGraphicsItem to QGraphicsScene QT
[英]Qt Removing a QGraphicsItem from QGraphicsScene with singleShot Timer?
虽然可以使用计时器和Qt的信号槽机制从场景中自动删除QGraphicsTextItem
QTimer::singleShot(1000, QGraphicsTextItem*, SLOT(deleteLater()));
其他图形对象(QGraphicsItem,QGraphicsEllipseItem)似乎不继承QObject,因此在编译时会导致错误:
错误:C2664:“ QTimer :: singleShot”:参数“ QObject *”中的参数2 von'QGraphicsEllipseItem *'
(无法转换/强制转换参数2 ...)
由于我希望在有限的时间内同时显示文本和某些图形,因此我的问题是:如何实现自动定时地清除上述“其他”对象?
QGraphicsItem
不能正常继承QObject
。 您需要像这样子类化QGraphicsEllipseItem
:
class AutoHidingItem : public QObject, public QGraphicsEllipseItem
{
Q_OBJECT
// ...
}
或者,您只需要让场景跟踪要隐藏的项目,然后在需要时将其隐藏即可。 (在子类别的场景或视图中留出一个插槽,用于隐藏或删除该项目。)
编辑:@thuga指出QGraphicsEllipseItem
不继承QObject
,而QGraphicsTextItem
已经继承。 编辑答案以显示这一点。
希望能有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.