Search code examples
pythonpyqt4drop-down-menu

dropdown menu with sub menu in pyqt4


how to create a drop down menu with sub menus that can execute an action when the element is selected? The data of the menu's are loaded from dictionary. I've tried the menu in qpushbutton but i think there's no sub menus for it. Here is an example of what i want to do, I only want the sub menus, but its too complicated for me. QPlainTextEdit With In Line Spell Check


Solution

  • You didn't say what did you do, but here's a simple example:

    from PyQt4 import QtGui
    
    app = QtGui.QApplication([])
    
    menu = QtGui.QMenu()
    
    sub_menu = QtGui.QMenu("Sub Menu")
    
    for i in ["a", "b", "c"]: #or your dict
        sub_menu.addAction(i) #it is just a regular QMenu
    
    menu.addMenu(sub_menu)
    
    menu.show()
    
    app.exec_()