Results 1 to 12 of 12

Thread: Strange mouseReleaseEvent behaviour.

  1. #1
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Question Strange mouseReleaseEvent behaviour.

    Hi all!

    Why if I press and release left or right mouse button, I only see "release" message instead of "release left" or "release right"?

    Qt Code:
    1. void CMyGLDrawer::mouseReleaseEvent(QMouseEvent *event) {
    2. qDebug("release");
    3. if (event->buttons() & Qt::LeftButton) {
    4. qDebug("release left");
    5. }
    6. if (event->buttons() & Qt::RightButton) {
    7. qDebug("release right");
    8. }
    9. event->accept();
    10. }
    To copy to clipboard, switch view to plain text mode 

    Thanks a lot for your help

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    try this code
    Qt Code:
    1. void CMyGLDrawer::mouseReleaseEvent(QMouseEvent *event) {
    2. qDebug("release");
    3. if (event->button() == Qt::LeftButton) {
    4. qDebug("release left");
    5. }
    6. if (event->button() == Qt::RightButton) {
    7. qDebug("release right");
    8. }
    9. event->accept();
    10. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. The following user says thank you to spirit for this useful post:

    ricardo (5th May 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    Works fine, changing buttons by button and comparer.

    By the way, if I press two buttons at the same time, and I move the mouse, how many events will I receive? 1 or 2?

    Thanks a lot.
    Last edited by ricardo; 5th May 2009 at 00:33.

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    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].

  6. The following user says thank you to spirit for this useful post:

    ricardo (5th May 2009)

  7. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange mouseReleaseEvent behaviour.

    Quote Originally Posted by spirit View Post
    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.
    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).
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  8. The following user says thank you to wysota for this useful post:

    ricardo (5th May 2009)

  9. #6
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    I talked about CMyGLDrawer::mouseReleaseEvent and QMouseEvent::buttons not about moveEvent.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  10. The following user says thank you to spirit for this useful post:

    ricardo (5th May 2009)

  11. #7
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    Quote Originally Posted by spirit View Post
    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.
    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 10:42.

  12. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    Quote Originally Posted by ricardo View Post
    Wait. Still don't understand.
    Which case? Mine or Spirit?
    I was talking about code snippent wich you posted.

    Quote Originally Posted by ricardo View Post
    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?
    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].

  13. The following user says thank you to spirit for this useful post:

    ricardo (5th May 2009)

  14. #9
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    Understood.
    Thanks a lot.

  15. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange mouseReleaseEvent behaviour.

    Quote Originally Posted by ricardo View Post
    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?
    Most likely four - two press and two release events.

    I'm currently experimenting with xev and it seems on X11 you would get three events - one press and two release.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  16. #11
    Join Date
    Apr 2009
    Posts
    132
    Thanks
    67
    Thanked 6 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Strange mouseReleaseEvent behaviour.

    Quote Originally Posted by wysota View Post
    Most likely four - two press and two release events.

    I'm currently experimenting with xev and it seems on X11 you would get three events - one press and two release.
    Really? One press event when you press 2 buttons??? Sounds strange, doesnt it?

  17. #12
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Strange mouseReleaseEvent behaviour.

    Quote Originally Posted by ricardo View Post
    Really? One press event when you press 2 buttons??? Sounds strange, doesnt it?
    No, actually I was wrong.

    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
    You can see two ButtonPush events reported, once for the left (1) and then for the right (3) mouse button.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Strange xml behaviour when opening the file.
    By cbarmpar in forum Qt Programming
    Replies: 5
    Last Post: 28th September 2008, 20:44
  2. qinputdialog strange behaviour
    By dreamer in forum Qt Programming
    Replies: 1
    Last Post: 11th May 2008, 19:29
  3. very strange behaviour
    By regix in forum Qt Programming
    Replies: 23
    Last Post: 20th July 2006, 17:38
  4. Replies: 1
    Last Post: 26th February 2006, 05:52
  5. [Qt 4.1] Strange behaviour with QTableView
    By fane in forum Qt Programming
    Replies: 1
    Last Post: 23rd January 2006, 06:17

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.