qt4 qgraphicsview 帮助
我已经用 pygtk 做了很多东西,但是我决定学习 pyqt,我被困在 qgraphicsview 上,我绝对不知道如何从我放置在图形视图上的项目(主要是鼠标事件)获取信号。我如何获取场景中各个项目的鼠标事件?
I've done lots of stuff with pygtk however i'm deciding to learn pyqt, im stuck at the qgraphicsview i have absolutley no idea how to get signals from the items i place on the graphics view, primarily mouse events.How do i get the mouse events from idividual items in a scene?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
QGraphicsItem 不是 QObject,不能发送信号,也不能接收槽。相反,您必须处理事件。您可以通过事件过滤器、对视图或场景进行子类化以拦截事件,或者简单地对项目本身进行子类化并实现事件处理函数(请参阅文档中的受保护成员函数)来实现此目的。也许这个例子可能会让人感兴趣: http://doc.trolltech.com/4.6/ GraphicsView-diagramscene.html 。
QGraphicsItem is not a QObject and cannot send signals, nor receive slots. Instead, you must handle events. You can do that either through an event filter, sub-classing the view or scene to intercept events or simply sub-classing the items themselves and implementing the event handling functions (see protected member functions in the documentation). Perhaps this example can be of interest: http://doc.trolltech.com/4.6/graphicsview-diagramscene.html .
创建项目后,立即将所需的信号连接到包含该项目的小部件的实例。
Right after you create an item, connect the signals you want from it to the instance of the widget that contains it.
另一种选择是放弃使用信号,并让 QGraphicItem 的实例通过保留对其父级的引用来直接调用其父级的方法。这不如使用信号漂亮,但最终它可以完成工作。
Another option is to just give up using signals and have your instance of QGraphicItem directly call a method of its parent by keeping a reference to it. This is less pretty than using signals but ultimately, it gets the job done.