Results 1 to 8 of 8

Thread: Easiest way to detect right mousebutton?

  1. #1
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Easiest way to detect right mousebutton?

    From the documentation:
    void QListWidget::itemPressed ( QListWidgetItem * item ) [signal]

    This signal is emitted with the specified item when a mouse button is pressed on an item in the widget.

    See also itemClicked() and itemDoubleClicked().
    I want to detect if the right mousebutton is pressed on a QListWidgetItem (in a QListWidget). How do I do this without catching all the mouse-events?

  2. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Easiest way to detect right mousebutton?

    You can try using QWidget::customContextMenuRequested( const QPoint& ) and detect what item( if any ) is at that position.

    This is always for the right mouse button.

    Regards

  3. #3
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Easiest way to detect right mousebutton?

    Subclass the QListWidget and redefine the QAbstractItemView::mousePressEvent() function. The QMouseEvent pointer that is passed can give you information about the button that was pressed and the position of the mouse-cursor (which you can translate to the right item).

    About marcel's idea: I think that the context-menu can be called in more than one way (some keyboards have a key for it, for example). So you might want to go with the subclassing method.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  4. #4
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Easiest way to detect right mousebutton?

    About marcel's idea: I think that the context-menu can be called in more than one way (some keyboards have a key for it, for example). So you might want to go with the subclassing method.
    But if a context menu key is pressed mousePressEvent won't work.
    But the function I proposed will, since Qt will detect the key ( at least I assume it will ). But the correct way would be top detect it.

    Regards

  5. #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: Easiest way to detect right mousebutton?

    Quote Originally Posted by Teuniz View Post
    I want to detect if the right mousebutton is pressed on a QListWidgetItem (in a QListWidget). How do I do this without catching all the mouse-events?
    What do you want to use that knowledge for?

  6. #6
    Join Date
    Mar 2006
    Location
    The Netherlands
    Posts
    300
    Thanks
    9
    Thanked 29 Times in 29 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: Easiest way to detect right mousebutton?

    Quote Originally Posted by marcel View Post
    But if a context menu key is pressed mousePressEvent won't work.
    But the function I proposed will, since Qt will detect the key ( at least I assume it will ). But the correct way would be top detect it.

    Regards
    Exactly my point.

    Teuniz did not say he wanted to intercept the context-menu. He wanted to intercept the right mouse button. Or so he said in his post.
    "The strength of a civilization is not measured by its ability to wage wars, but rather by its ability to prevent them." - Gene Roddenberry

  7. #7
    Join Date
    Aug 2006
    Location
    The Netherlands
    Posts
    64
    Thanks
    6
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Easiest way to detect right mousebutton?

    What do you want to use that knowledge for?
    I made a small hobbyproject: http://www.teuniz.net/q3spy/
    As you can see, there is a list of servers. When you dubbelclick with the
    left mousebutton, the (external) game will start. Now I want to make it
    possible to view/edit the properties of a server by rightclicking on a server
    instead of navigating via the menu.

  8. #8
    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: Easiest way to detect right mousebutton?

    You have to reimplement mouseReleaseEvent then.

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.