your code will work in this case, i.e. if you pressed two or more mouse buttons then QMouseEvent::buttons will retrun all pressed buttons, that's why this function doesn't work for one button.
your code will work in this case, i.e. if you pressed two or more mouse buttons then QMouseEvent::buttons will retrun all pressed buttons, that's why this function doesn't work for one button.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
ricardo (5th May 2009)
I think that it doesn't work because it returns the current state of the buttons and so in release event no buttons are in the pressed state while in mouse move they are. So the same code put in mouseMove will work while it doesn't with mouseRelease. button() on the other hand returns the button that caused the event (regardless of its current state).
ricardo (5th May 2009)
I talked about CMyGLDrawer::mouseReleaseEvent and QMouseEvent::buttons not about moveEvent.![]()
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
ricardo (5th May 2009)
Wait. Still don't understand.
Which case? Mine or Spirit?
if I press two buttons at the same time, and I release them at the same time, how many event would I receive? 1 or 2?
I think moving the mouse I will receive only 1, so I have to use:
(event->buttons() & Qt::LeftButton) and (event->buttons() & Qt::RightButton)
But not on release and press, as I guess I will only receive 1. So I have to use:
(event->button() == Qt::LeftButton) or (event->button() == Qt::RightButton)
Am I right?
Thanks a lot for your help and time.
Last edited by ricardo; 5th May 2009 at 11:42.
I was talking about code snippent wich you posted.
in that case you receive one event, but QMouseEvent::buttons will return two buttons.
but if you need to determinate wich buttons have been pressed while moving a mouse then you need to use wysota's suggestion.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
ricardo (5th May 2009)
Understood.
Thanks a lot.
No, actually I was wrong.
You can see two ButtonPush events reported, once for the left (1) and then for the right (3) mouse button.ButtonPress event, serial 31, synthetic NO, window 0x5800001,
root 0x13c, subw 0x5800002, time 36532044, (48,35), root:(735,101),
state 0x0, button 1, same_screen YES
EnterNotify event, serial 31, synthetic NO, window 0x5800001,
root 0x13c, subw 0x0, time 36532044, (48,35), root:(735,101),
mode NotifyGrab, detail NotifyInferior, same_screen YES,
focus YES, state 256
KeymapNotify event, serial 31, synthetic NO, window 0x0,
keys: 60 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
ButtonPress event, serial 31, synthetic NO, window 0x5800001,
root 0x13c, subw 0x5800002, time 36532068, (48,35), root:(735,101),
state 0x100, button 3, same_screen YES
ButtonRelease event, serial 31, synthetic NO, window 0x5800001,
root 0x13c, subw 0x5800002, time 36537716, (48,35), root:(735,101),
state 0x500, button 3, same_screen YES
ButtonRelease event, serial 31, synthetic NO, window 0x5800001,
root 0x13c, subw 0x5800002, time 36537740, (48,35), root:(735,101),
state 0x100, button 1, same_screen YES
Bookmarks