mouseMoved 忽略 QCursor.setPos()?
当光标位于我的小部件内时,我正在调用 QCursor.setPos() 。当我这样做时,mouseMoveEvent 会被调用,而我不希望它被调用。在 Java/Swing 中,我可以移动光标而不发送事件。我可以做类似的事情,所以调用 QCursor.setPos() 所以不发送 mouseMoveEvent 吗?
I'm calling QCursor.setPos() while the cursor is inside my widget. When I do, mouseMoveEvent is called, when I don't want it to be. In Java/Swing I can move the cursor without sending events. Can I do something similar so calls to QCursor.setPos() so don't send a mouseMoveEvent?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这似乎对我有用:
This seems to work for me:
貌似没有办法在不触发mouseMoveEvent的情况下setPos,
也许您考虑创建一个 :
并将其作为一个标志来证明您的逻辑正在运行?
我使用此方法来调用 QListWidgetItem::setSelected
没有 make QListWidget::itemSelectionChanged 触发我的代码。
Looks like there is no way to setPos without trigger mouseMoveEvent,
maybe you consider create a :
and make it as a flag for provent your logic running?
I use this method for calling QListWidgetItem::setSelected
without make QListWidget::itemSelectionChanged trigger my code.
我最终只是跟踪鼠标移动之间的差异,因此,例如,如果我的鼠标向右移动 5 次,我会存储这 5 次,并忽略下一个事件,如果它向左移动 5 次(这意味着它可能是由 setPos 调用的)。不是很优雅,但它看起来工作可靠。
I ended up just keeping track of the difference in between mouse movements, so if I get a mouse movement of 5 to the right, for example, I store the five and ignore the next event if it moves me 5 to the left (which means it's probably called by setPos). Not really elegant, but it appears to work reliably.