开发者

mouseMoved to ignore QCursor.setPos()?

开发者 https://www.devze.com 2023-02-04 08:38 出处:网络
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 s开发者_运维问答ending e

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 s开发者_运维问答ending events. Can I do something similar so calls to QCursor.setPos() so don't send a mouseMoveEvent?


This seems to work for me:

myWidget->clearFocus();
QCursor::setPos(pos);
myWidget->setFocus();


Looks like there is no way to setPos without trigger mouseMoveEvent, maybe you consider create a :

bool disableMoveProcess;

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消