Results 1 to 7 of 7

Thread: Right-Click menu on a pushButton doesn't show up

  1. #1
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Question Right-Click menu on a pushButton doesn't show up

    Hi,

    I'm trying to add a right-click menu on a pushButton, but the menu doesn't show up??
    Anyone to help?

    Qt Code:
    1. def addChannelsMenu(self):
    2. chmenu = QtGui.QMenu()
    3. chmenu.addAction('testing')
    4. chmenu.addAction('testing1')
    5. chmenu.addSeparator()
    6. chmenu.addAction('testing2')
    7. #self.channelsBtn.setMenu(chmenu)
    8.  
    9. #self.channelsBtn.showMenu()
    10. self.zoomBtn.setMenu(chmenu)
    To copy to clipboard, switch view to plain text mode 


    I tried repainting but it wouldn't help either:
    Qt Code:
    1. self.zoomBtn.repaint()
    To copy to clipboard, switch view to plain text mode 

    I'm on Fedora8 at the moment.

  2. #2
    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: Right-Click menu on a pushButton doesn't show up

    setMenu() doesn't set a context menu. If you want a context menu, you have three choices - either reimplement the contextMenuEvent() method of the button or catch the customContextMenuRequested() signal or add actions to the button and set the context menu policy accordingly (each of the solutions needs its own setting of that policy).
    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.


  3. #3
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Right-Click menu on a pushButton doesn't show up

    thanks for hints wysota,
    Any chance you had some examples of one of the approaches?
    Looking at the documentation http://www.riverbankcomputing.co.uk/...n.html#setMenu
    "ssociates the popup menu menu with this push button. This turns the button into a menu button"
    there should be a menu popping but it doesn't - do you know what I am missing here?

  4. #4
    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: Right-Click menu on a pushButton doesn't show up

    Quote Originally Posted by qtpyqt View Post
    Any chance you had some examples of one of the approaches?
    There are numerous examples in the docs and standalone Qt examples distributed with Qt itself.

    Looking at the documentation http://www.riverbankcomputing.co.uk/...n.html#setMenu
    "ssociates the popup menu menu with this push button. This turns the button into a menu button"
    there should be a menu popping but it doesn't - do you know what I am missing here?
    You are missing the fact that the menu is not a context menu - it is not triggered with right mouse button but with a left one.
    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.


  5. #5
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Right-Click menu on a pushButton doesn't show up

    I will dig into the docs to find examples, thx.
    Although one thing still confuses me - if that menu was supposed to show up after left-click it still didn't :/
    Got an idea why?

    cheers

  6. #6
    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: Right-Click menu on a pushButton doesn't show up

    Maybe it went out of scope and got deleted.
    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.


  7. #7
    Join Date
    May 2010
    Posts
    9
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11

    Default Re: Right-Click menu on a pushButton doesn't show up

    yepp - I just missed to parent the menu to the QButton and it's correct - the menu doesn't pop up as a right-click menu - it actually turns the whole button into a menu button.
    cheers

Similar Threads

  1. twice execution of click on pushbutton?
    By rambo83 in forum Newbie
    Replies: 8
    Last Post: 10th November 2009, 12:21
  2. pushButton click event
    By aj2903 in forum Qt Programming
    Replies: 1
    Last Post: 9th June 2009, 11:19
  3. Can't click menubar items / QPixMap doesn't show
    By richardander in forum Qt Programming
    Replies: 1
    Last Post: 30th December 2008, 10:45
  4. Working out table's current row from pushbutton click
    By shooogun in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2008, 23:40
  5. Right click menu
    By ^NyAw^ in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:22

Tags for this Thread

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.