PDA

View Full Version : QMouseEvent data non-portable? Help with multibutton issue



weevil
14th June 2010, 22:37
I'm trying to understand what's going on when I attempt to register a multibutton mouse event in mousePress/ReleaseEvent(). On Ubuntu 9.10, when I click both the left and right mousebuttons within ~300 ms of each other, only one press event is being received by the widget, and the value of both event->button() and event->buttons() is 4 (for Qt::MouseButton and Qt::MouseButtons), and similarly only one release event is received, with event->button() being 4, and event->buttons() 0. It should be noted that for both Qt::MouseButton and Qt::MouseButtons, 4 is set to MidButton.

When the left and mouse button clicks aren't nearly simultaneous (>~300ms) I'm getting two press events and two release events. Here's a little chart of the values returned by event->button() and event->buttons() in that order base on the order of which button was pressed (1 == Qt::MouseButton and Qt::MouseButton LeftButton, 2 == RightButton, 3 == Qt::LeftButton | Qt::RightButton)

mousePressEvents mouseReleaseEvents
leftButton -> rightButton leftButton - > rightButton
1,1 2,3 1,2 2,0
leftButton -> rightButton rightButton -> leftButton
1,1 2,3 2,1 1,0
rightButton -> leftButton rightButton -> leftButton
2,2 1,3 2,1 1,0
rightButton -> leftButon leftButton -> rightButton
2,2 1,3 1,2 2,0

So for mousePressEvent in the case of an left and right button multiclick registering as separate events, event->Buttons() returns Qt::LeftButton | Qt::RightButton for the second press event, but neither release event registers Qt::LeftButton | Qt::RightButton for event->buttons(), but the first release event received does return a 1 or 2 for event->buttons(), whereas isolated single click events return 0.

The kicker is when I actually hit the middle mouse button in Ubuntu. Then the press and release events work like I detailed above for near simultaneous left and right clicks, but when I try to do a quick left and right button click again, I'm only getting separate clicks like I described in the second part. It takes restarting the operating system to restore Qt to interpreting fast multibutton presses as one event, until I again hit the middle mouse button. It doesn't matter whether I hit the middle mouse button outside of the Qt application or inside. I can't find any documentation about any of this other than the sparse QMouseEvent documentation, but it seems like the button press and release data is highly dependant on the underlying window manager, and thus somewhat unportable.

So I'd like to know why GNOME initially passes fast multibutton clicks to Qt as one event as Qt::MidButton, until we use the middle button and then only registers actual mouse wheel clicks as Qt::MidButton. Also I'd like to know how to handle dealing with mousePress/ReleaseEvents in a portable fashion. Will testing for event->buttons() == (Qt::LeftButton | Qt::RightButton) in mousePressEvent(), and event->buttons() != Qt::NoButton in mouseReleaseEvent() give me what I want on all platforms?