voodoogiant
voodoogiant

Reputation: 2148

mouseMoved to ignore QCursor.setPos()?

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?

Upvotes: 1

Views: 1560

Answers (3)

Fox
Fox

Reputation: 2138

This seems to work for me:

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

Upvotes: 3

voodoogiant
voodoogiant

Reputation: 2148

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.

Upvotes: 0

linjunhalida
linjunhalida

Reputation: 4655

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.

Upvotes: 0

Related Questions