Results 1 to 9 of 9

Thread: mousePressEvent - Problems handling right and left mouse buttons together

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2010
    Posts
    12
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows
    Thanks
    1

    Default Re: mousePressEvent - Problems handling right and left mouse buttons together

    Quote Originally Posted by tbscope View Post
    Events are like a FIFO, first in, first out. When you first click the left button and then the right, the left button event is first and then the right.
    When you click both buttons at the same time on your mouse, it depends. You, as a human, can NOT press them at the same time, if you do, it's pure luck. One button will always be first. Which one is a guess.

    Now, how to solve this?
    You could make use of a timer. For example, the user has 500ms to press both buttons. If both release or press events happen before the timer times out, you could use them as a multi touch event.
    Then I must be misunderstanding what's going on. I was thinking there were two mouse press events occuring in the scenario I described, where the first is either a left or right button press, and the second event registers both left and right button presses. You make it sound like there's one event that registers a left click say, and the other registers a right click? This doesn't seem to jive with my experimenting and the documenation, by testing if( event->buttons() == (Qt::LeftButton | Qt::RightButton) ), the following block statements are executed.

    I had thought of using a timer, but as I said I'd like to find a way to not do that, as it makes the UI seem laggy. It is my fallback plan though.

  2. #2
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    1,938
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows
    Thanked 268 Times in 268 Posts
    Wiki edits
    20

    Default Re: mousePressEvent - Problems handling right and left mouse buttons together

    Quote Originally Posted by weevil View Post
    I was thinking there were two mouse press events occuring in the scenario I described, where the first is either a left or right button press, and the second event registers both left and right button presses. You make it sound like there's one event that registers a left click say, and the other registers a right click?
    I see what you mean.
    You can click the left mouse button and keep it pressed. There will be a left mouse button press event. It might be repeated too when holding it.
    Now, while you keep the left mouse button pressed, you press the right button. There will now be a new press event for the right button.
    They do not appear at the same time and the second press event is only for the right button.

    You then want to check if both press events happened in a certain amount of time (if necessary) or just check if they are both pressed independent of the time.

  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11
    Thanks
    1
    Thanked 94 Times in 86 Posts

    Default Re: mousePressEvent - Problems handling right and left mouse buttons together

    Mouse events are always serialized; even if you manage to press both mouse buttons precisely at the same time, the OS is going to convert that into two seperate events and send them along one after the other.

    The best you can do is note the state of the event by examining buttons() and checking to see whether both buttons happen to be down, which will be the case for one of the pair of events you'll receive. If you want different behavior when only one button is down, though, the only way to implement that is to use an interval timer that determines when two clicks are "close enough" together to count as a single event.

Similar Threads

  1. Replies: 4
    Last Post: 30th May 2010, 12:55
  2. Emulating Enter key with left mouse click
    By wconstan in forum Newbie
    Replies: 6
    Last Post: 30th December 2009, 16:16
  3. how align some buttons in QToolbar from right to left?
    By davi_all4one in forum Qt Programming
    Replies: 3
    Last Post: 7th September 2009, 11:15
  4. combining Alt + Left Mouse Button
    By speedracer in forum Qt Programming
    Replies: 1
    Last Post: 3rd June 2009, 13:29
  5. left/right panel with buttons
    By swiety in forum Qt Programming
    Replies: 1
    Last Post: 5th January 2008, 13:12

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
  •  
Qt is a trademark of The Qt Company.