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.
精彩评论