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?
Code:
def addChannelsMenu(self):
chmenu.addAction('testing')
chmenu.addAction('testing1')
chmenu.addSeparator()
chmenu.addAction('testing2')
#self.channelsBtn.setMenu(chmenu)
#self.channelsBtn.showMenu()
self.zoomBtn.setMenu(chmenu)
I tried repainting but it wouldn't help either:
Code:
self.zoomBtn.repaint()
I'm on Fedora8 at the moment.
:confused:
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).
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?:confused:
Re: Right-Click menu on a pushButton doesn't show up
Quote:
Originally Posted by
qtpyqt
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.
Quote:
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?:confused:
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.
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
Re: Right-Click menu on a pushButton doesn't show up
Maybe it went out of scope and got deleted.
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:cool: