python - Create submenu in PyQt -
i have simple code menu in pyqt, problem doesn't show submenu. want show while hovering on "more". wrong?
class menu(qtgui.qmenu): def __init__(self, parent=none): qtgui.qmenu.__init__(self, "menu", parent) sub_menu = qtgui.qmenu("sub menu") icon = qtgui.qicon.fromtheme("edit-paste") item = qtgui.qaction(icon, "more", self) self.addaction(item) icon = qtgui.qicon.fromtheme("edit-copy") item = qtgui.qaction(icon, "submenu item 1", self) item.triggered.connect(self.function) sub_menu.addaction(item) icon = qtgui.qicon.fromtheme("edit-copy") item = qtgui.qaction(icon, "submenu item 2", self) item.triggered.connect(self.function) sub_menu.addaction(item) self.addmenu(sub_menu) icon = qtgui.qicon.fromtheme("close") item = qtgui.qaction(icon, "&exit", self) item.triggered.connect(self.quit_f) self.addaction(item) def function(self): qtgui.qmessagebox.about(self.parent(), "about", "test") def quit_f(self): sys.exit(0)
you must provide parent when create submenu:
sub_menu = qtgui.qmenu("sub menu", parent=self) ... self.addmenu(sub_menu)
note: alternative, more concise way create submenus:
sub_menu = self.addmenu("sub menu")
Comments
Post a Comment