在 C++ 中将事件从 QGraphicsScene 传递到 QGraphicsItem与Qt
我有一个扩展 QGraphicsScene 的基类...
class BaseScene : public QGraphicsScene
在该类中是受保护的事件...
void BaseScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
有一些用户点击,我需要将事件传递给 QGraphicsScene,因为
QGraphicsItem
还包含“mousePressEvent
”。
如何将我选择的事件从 QGprahicsScene
分配到特定的 QGraphicsItem
?
谢谢。
I have a base class extending QGraphicsScene...
class BaseScene : public QGraphicsScene
in that class is the protected event...
void BaseScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
There are some user clicks where I need to pass the event on to the QGraphicsItem inside the QGraphicsScene
, as the QGraphicsItem
also contains a 'mousePressEvent
'.
How can I propergate down events of my choosing from the QGprahicsScene
to a specific QGraphicsItem
?.
Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在重新实现的 mousePressEvent() 中添加:
这将调用默认实现:“默认实现取决于场景的状态。如果存在鼠标抓取器项目,则事件将发送到鼠标抓取器。否则,将转发到从事件中接受场景位置处的鼠标事件的最上面的项目,并且该项目立即成为鼠标抓取器项目。”
希望这有帮助
In your reimplemented mousePressEvent() add:
This will call the default implementation : "The default implementation depends on the state of the scene. If there is a mouse grabber item, then the event is sent to the mouse grabber. Otherwise, it is forwarded to the topmost item that accepts mouse events at the scene position from the event, and that item promptly becomes the mouse grabber item."
Hope this helps