检测鼠标何时按下按钮进入 QGraphicsItem
我想在按下鼠标按钮时检测鼠标光标何时移入 QGraphicsItem
上,即在鼠标进入项目之前按下按钮。我的第一个想法是使用 hoverEnterEvent
,但按下鼠标左键时似乎没有触发。我的另一个想法是使用dragEnterEvent
,但它似乎根本没有触发(即使我已经使用setAcceptDrops(True)
。
检测的最佳方法是什么当光标移动到项目顶部并按下鼠标按钮时?
I want to detect when the mouse cursor moves in over a QGraphicsItem
while a mouse button is pressed, i.e. the button is pressed before the mouse enters the item. My first idea was to use hoverEnterEvent
, but it doesn't seem to trigger when the left mouse button is pressed. My other idea was to use dragEnterEvent
, but it doesn't seem to trigger at all (even though I have used setAcceptDrops(True)
.
What is the best way to detect when the cursor moves on top of an item and the mouse button is pressed?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我刚刚发现这个问题,我知道它很旧,但我希望我的答案对遇到这个问题的人有用。
在
QGraphicsView
或QGraphicsScene
派生类中重写mouseMoveEvent
方法并检查事件的buttons
属性以了解哪些按钮目前按下。这是我正在开发的一个小项目中的 PyQt4 示例代码:I just found this question, I know it's old, but I hope my answer will be useful for someone with this problem.
In the
QGraphicsView
orQGraphicsScene
derived class override themouseMoveEvent
method and check the event'sbuttons
property to know what buttons are currently pressed. Here's an example code in PyQt4 from a small project I'm working on:尝试使用
mouseMoveEvent()
和mousePressEvent()
。如果它们不能帮助您,那么您需要重新实现虚拟方法,检查内部的鼠标按钮状态并调用适当的事件处理程序。
Try the
mouseMoveEvent()
andmousePressEvent()
. If they do not help you then you'll need to reimplement virtual methodCheck the mouse button state inside and call the appropriate event handler.