本文整理汇总了Python中PyQt4.QtGui.QMenu.insertAction方法的典型用法代码示例。如果您正苦于以下问题:Python QMenu.insertAction方法的具体用法?Python QMenu.insertAction怎么用?Python QMenu.insertAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtGui.QMenu
的用法示例。
在下文中一共展示了QMenu.insertAction方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: registerAction
# 需要导入模块: from PyQt4.QtGui import QMenu [as 别名]
# 或者: from PyQt4.QtGui.QMenu import insertAction [as 别名]
def registerAction(self, action, menuName, callback=None):
""" register an action to the manager's main menu """
if not hasattr(self, '_registeredDbActions'):
self._registeredDbActions = {}
if callback is not None:
invoke_callback = lambda x: self.invokeCallback(callback)
if menuName is None or menuName == "":
self.addAction(action)
if menuName not in self._registeredDbActions:
self._registeredDbActions[menuName] = list()
self._registeredDbActions[menuName].append(action)
if callback is not None:
QObject.connect(action, SIGNAL("triggered(bool)"), invoke_callback)
return True
# search for the menu
actionMenu = None
helpMenuAction = None
for a in self.menuBar.actions():
if not a.menu() or a.menu().title() != menuName:
continue
if a.menu() != self.menuHelp:
helpMenuAction = a
actionMenu = a
break
# not found, add a new menu before the help menu
if actionMenu is None:
menu = QMenu(menuName, self)
if helpMenuAction is not None:
actionMenu = self.menuBar.insertMenu(helpMenuAction, menu)
else:
actionMenu = self.menuBar.addMenu(menu)
menu = actionMenu.menu()
menuActions = menu.actions()
# get the placeholder's position to insert before it
pos = 0
for pos in range(len(menuActions)):
if menuActions[pos].isSeparator() and menuActions[pos].objectName().endswith("_placeholder"):
menuActions[pos].setVisible(True)
break
if pos < len(menuActions):
before = menuActions[pos]
menu.insertAction(before, action)
else:
menu.addAction(action)
actionMenu.setVisible(True) # show the menu
if menuName not in self._registeredDbActions:
self._registeredDbActions[menuName] = list()
self._registeredDbActions[menuName].append(action)
if callback is not None:
QObject.connect(action, SIGNAL("triggered(bool)"), invoke_callback)
return True