Results 1 to 6 of 6

Thread: handling right click

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default handling right click

    Hi everyone, can someone explain me how to handle right clicks, please? I found on the web that you have to use some new classes, but I don't know how to. Please try to be as much precise as you can because I am quite a beginner. Thank you in advance.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: handling right click

    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Jan 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: handling right click

    Thank you for your reply. I would like to connect the right button click to a function called function() which is in a class called Class. So what should I exactly write in the code?
    I also found this
    Qt Code:
    1. void mouseReleaseEvent(QMouseEvent* e)
    2. {
    3. if (event->button() & RightButton)
    4. //???
    5. }
    To copy to clipboard, switch view to plain text mode 
    Is it ok for what I want to do? And what should I write where there are the question marks? Thank you.

  4. #4
    Join Date
    Oct 2010
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: handling right click

    Hi,

    just call your function in the mouseReleaseEvent like this:

    Qt Code:
    1. void mouseReleaseEvent(QMouseEvent *event)
    2. {
    3. if(event->button() & Qt::RightButton)
    4. {
    5. // call your specific function
    6. this->doSth();
    7. }
    8. }
    To copy to clipboard, switch view to plain text mode 

  5. #5
    Join Date
    Jan 2011
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: handling right click

    Thank you. The thing is that I have many buttons in a QButtonGroup and I want call a function function() on only one of them when I right-click it. Do you know how to do it?

  6. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: handling right click

    You have two options:
    1. Subcalss QPushButton, override the mousePressEvent() or mouseReleaseEvent() based on your needs, and emit a signal from there.
    You can then connect that signal to any slot of any other QObject class.
    2. Use an event filter in the parent class of the buttons, catch the mousePressEvent (ore released event) and emit a signal form there, which again, you can connect to any other known instance of any other QObject class.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. Proper handling "Cancel" click for QWizard
    By Splinter in forum Qt Programming
    Replies: 4
    Last Post: 17th September 2012, 14:34
  2. Handling mouse click events in QGraphicsItem
    By Luc4 in forum Qt Programming
    Replies: 7
    Last Post: 5th March 2010, 16:12
  3. Replies: 6
    Last Post: 5th June 2009, 09:38
  4. Replies: 2
    Last Post: 11th January 2009, 23:24
  5. Replies: 5
    Last Post: 12th January 2006, 15:40

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.