同时触发多个QGraphicsItem的mouseMoveEvent
当我选择多个 QGraphicsItem(使用 Ctrl 键)时,我可以将它们移动到一起,但 mouseMoveEvent 仅针对实际接收事件的项目触发。有没有办法让每个选定的项目都收到该事件?我在 Qt 的文档中找不到它。
我可以将选定的项目分组在一起并在 QGraphicsView 的 mouseMoveEvent 中处理它吗?
非常感谢您的帮助:)
When I select several QGraphicsItem (with Ctrl key) I can move them together, but the mouseMoveEvent is triggered only for the item that actually receives the event. Is there a way to make every selected items receive the event ? I can't find it in Qt's doc.
Could I group selected items together and handle it within QGraphicsView's mouseMoveEvent ?
Thanks a lot for any help :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
不,据我所知,没有默认的方法可以做你想做的事。您可以执行以下操作:
QGraphicsScene
并实现mouseMoveEvent
itemAt< 检查事件位置是否有项目/code> 函数
isSelected
),则获取场景中所有选定的项目。示例代码如下:
No there is no default way to do what you want as far as I know. Something you could do is the following:
QGraphicsScene
and implement themouseMoveEvent
itemAt
functionisSelected
), get all selected items of the scene.Sample code follows:
我正在阅读您问题的字里行间,但听起来在您的
QGraphicsItem
类上实现QGraphicsItem::itemChange
可能会更好。每当位置发生变化时(无论是通过鼠标、键盘、编程等),都会调用此函数。如果您愿意,您甚至可以取消更改。I'm reading between the lines of your question a little, but it sounds like you might be better served by implementing
QGraphicsItem::itemChange
on yourQGraphicsItem
class(es). This will get called whenever the position changes--whether by mouse, keyboard, programmatic, etc. You can even cancel the change if you want to.