im just a beginner in PyQT.
and im not sure if my thread title is the correct thing to put for my problem.
im having a problem creating a popmenu on a Qpushbutton.
based on the doc of QT docs
i need to make a QPushButton.setMenu (self, QMenu menu)
but i really dont know where to start.. i cant find a sample on how to use this.
please help me making one.
The basic idea is that you first have to create a
QMenu, then use thesetMenumethod to attach it to your push button. If you look at theQMenudocumentation, you’ll see that there is a method calledaddActionthat will add menu items to your newly createdQMenu.addActionis overloaded, so there are a lot of different ways to call it. You can use icons in your menu, specify keyboard shortcuts and other things. To keep things simple though, let’s just add a menu item and give it a method to call if that item is selected.Here we’ve created a push button (creatively named
pushbutton). We then create a menu (again creatively namedmenu) usingQtGui.QMenu(). The actions are created by callingaddActionand giving it a string that will be used as the menu item text and a method (self.Action1 or self.Action2) that will be called if that menu item is selected. Then we call thesetMenumethod ofpushbuttonto assign our menu to it. When you run it and select an item, you should see text printed corresponding to the selected item.That’s the basic idea. You can look through the QMenu docs to get a better idea of the functionality of QMenu.