Pregunta

From what i understood from the internet resources, I could create a Popup menu of QActions on the Qtoolbar by using Qtoolbuttonpopup mode.

So, I created a QMenu and added a few QActions to it by using QMenu.addAction.

After that i have created a QToolButton and set the ToolButtonPopupMode to 2. Followed by setting the QMenu i have created above as the menu for it by using .setMenu(QMenu)

    SettingMenu = QtGui.QMenu()
    SettingMenu.addAction(Action1)
    SettingMenu.addAction(Action2)

    SettingButton = QtGui.QToolButton()
    SettingButton.setIcon(QtGui.QIcon(QtGui.QPixmap(':/setting.png')))
    SettingButton.ToolButtonPopupMode(2)
    SettingButton.setMenu(SettingMenu)

from the above code, i am expecting to have a Qtoolbutton on my toolbar and when i click on it, it should pop up a menu with 2 Actions. But when i run the code, all i see is a Qtoolbutton on my toolbar but when i click the Qtoolbutton it doesn't create any pop up menu.

Am i doing this wrong? How do i create a toolbutton that create a pop up menu of actions upon user click?

¿Fue útil?

Solución

ToolButtonPopupMode is an enumerating type. All the values in that enum are instances of that type. Because it inherits from int, calling it with an integer returns the same integer. However, you want to set the popupMode property, so use setPopupMode(2).

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top