adding submenu in pyqt QWidget
Asked Answered
P

1

8

I know its very basic question but I am little bit confused, probably I am forgetting something.

I am trying to add a sub menu "Preview" to the "Tools" in the QMenuBar()

so far 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 guess this is not the correct way to add a sub menu

Poultice answered 5/2, 2013 at 11:50 Comment(0)
K
12

Sub menu should be a QMenu, not QAction:

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

It can be a bit more simple if you used convenience methods:

tools = fileMenu.addMenu('&Tools')
prevMenu = tools.addMenu('Preview')
prevAction = prevMenu.addAction('Using &Nuke')
Kesler answered 5/2, 2013 at 13:2 Comment(1)
Thanks for including both versions! Convenience methods are certainly nice when you can use them (but you can't always use them).Crossarm

© 2022 - 2024 — McMap. All rights reserved.