Adding a submenu to pyqt QWidget

I know his very simple question, but I'm a little confused, maybe I forgot something.

I am trying to add the "Preview" submenu to the "Tools" in QMenuBar ()

still this is what i am trying to do

tools = fileMenu.addMenu('&Tools')
prevAction = QtGui.QAction('Preview',self)
prevInNuke = QtGui.QAction("Using &Nuke",prevAction)
tools.addAction(prevAction)
prevAction.addAction(prevInNuke)

but I think this is not the right way to add a submenu

+5
source share
1 answer

The submenu should be QMenu, and not QAction:

tools = fileMenu.addMenu('&Tools')
prevMenu = QtGui.QMenu('Preview',self)
prevInNuke = QtGui.QAction("Using &Nuke",prevAction)
tools.addMenu(prevMenu)
prevAction.addAction(prevInNuke)

It might be a little easier if you used convenient methods:

tools = fileMenu.addMenu('&Tools')
prevMenu = tools.addMenu('Preview')
prevAction = prevMenu.addAction('Using &Nuke')
+8
source

All Articles