本文整理汇总了Python中PyQt5.QtWidgets.QMenu方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QMenu方法的具体用法?Python QtWidgets.QMenu怎么用?Python QtWidgets.QMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QMenu方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: contextMenuEvent
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def contextMenuEvent(self, event):
right_click_menu = Qw.QMenu(self)
act_open = right_click_menu.addAction('Open')
act_open.triggered.connect(self.parent().parent().right_clk_open)
act_open_path = right_click_menu.addAction('Open Path')
act_open_path.triggered.connect(self.parent().parent().right_clk_path)
right_click_menu.addSeparator()
act_copy_path = right_click_menu.addAction('Copy Path')
act_copy_path.triggered.connect(self.parent().parent().right_clk_copy)
right_click_menu.exec_(event.globalPos())
# THE PRIMARY GUI DEFINING INTERFACE WIDGET, THE WIDGET WITHIN THE MAINWINDOW
示例2: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def __init__(self, items, parent=None):
super(ButtonLineEdit, self).__init__(parent)
self.menu = QtWidgets.QMenu()
for i in items:
self.menu.addAction(i)
self.button = QtWidgets.QToolButton(self)
self.button.setStyleSheet('border: 0px; padding: 0px;')
self.button.setCursor(QtCore.Qt.ArrowCursor)
self.button.triggered.connect(self.menu_action_triggered)
self.button.setPopupMode(QtWidgets.QToolButton.InstantPopup)
self.button.setMenu(self.menu)
frameWidth = self.style().pixelMetric(QtWidgets.QStyle.PM_DefaultFrameWidth)
buttonSize = self.button.sizeHint()
self.setAlignment(QtCore.Qt.Alignment(QtCore.Qt.AlignHCenter))
self.setStyleSheet('QLineEdit {padding-right: %dpx; }' % (buttonSize.width() + frameWidth + 1))
self.setMinimumSize(max(self.minimumSizeHint().width(), buttonSize.width() + frameWidth*2 + 2),
max(self.minimumSizeHint().height(), buttonSize.height() + frameWidth*2 + 2))
self.setMaximumWidth(100)
示例3: show_context_menu
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def show_context_menu(self, point):
"""Show the context menu."""
index = self.indexAt(point)
if index.isValid():
item = self.model().data(index, downloads.ModelRole.item)
else:
item = None
self._menu = QMenu(self)
actions = self._get_menu_actions(item)
for (name, handler) in actions:
if name is None and handler is None:
self._menu.addSeparator()
else:
assert name is not None
assert handler is not None
action = self._menu.addAction(name)
action.triggered.connect(handler)
if actions:
self._menu.popup(self.viewport().mapToGlobal(point))
示例4: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def __init__(self, parent):
super().__init__()
# set ui direction
ui_direction = parent.persepolis_setting.value('ui_direction')
if ui_direction == 'rtl':
self.setLayoutDirection(Qt.RightToLeft)
elif ui_direction in 'ltr':
self.setLayoutDirection(Qt.LeftToRight)
# creating context menu
self.category_tree_menu = QMenu(self)
# connecting activation event
self.activated.connect(parent.categoryTreeSelected)
self.pressed.connect(parent.categoryTreeSelected)
示例5: applied_custom_menu
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def applied_custom_menu(self, point):
index = self.applied_tree_view.indexAt(point)
address = index.data(FIRSTUI.ROLE_ADDRESS)
if not address:
return
menu = QtWidgets.QMenu(self.applied_tree_view)
goto_action = QtWidgets.QAction('&Go to Function', self.applied_tree_view)
goto_action.triggered.connect(lambda:IDAW.Jump(address))
menu.addAction(goto_action)
metadata_id = index.data(FIRSTUI.ROLE_ID)
if metadata_id:
history_action = QtWidgets.QAction('View &History', self.applied_tree_view)
history_action.triggered.connect(lambda:self._metadata_history(metadata_id))
menu.addAction(history_action)
menu.exec_(QtGui.QCursor.pos())
示例6: custom_menu
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def custom_menu(self, point):
index = self.tree_view.indexAt(point)
address = index.data(FIRSTUI.ROLE_ADDRESS)
if not address:
return
menu = QtWidgets.QMenu(self.tree_view)
goto_action = QtWidgets.QAction('&Go to Function', self.tree_view)
goto_action.triggered.connect(lambda:IDAW.Jump(address))
menu.addAction(goto_action)
metadata_id = index.data(FIRSTUI.ROLE_ID)
if metadata_id:
history_action = QtWidgets.QAction('View &History', self.tree_view)
history_action.triggered.connect(lambda:self.metadata_history(metadata_id))
menu.addAction(history_action)
menu.exec_(QtGui.QCursor.pos())
示例7: add_menu
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def add_menu(path):
if not hasattr(mw, 'custom_menus'):
mw.custom_menus = {}
if len(path.split('::')) == 2:
parent_path, child_path = path.split('::')
has_child = True
else:
parent_path = path
has_child = False
if parent_path not in mw.custom_menus:
parent = QMenu('&' + parent_path, mw)
mw.custom_menus[parent_path] = parent
mw.form.menubar.insertMenu(mw.form.menuTools.menuAction(), parent)
if has_child and (path not in mw.custom_menus):
child = QMenu('&' + child_path, mw)
mw.custom_menus[path] = child
mw.custom_menus[parent_path].addMenu(child)
示例8: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def __init__(self, icon, parent, main_app, learning_mode):
self.main_app = main_app
QtWidgets.QSystemTrayIcon.__init__(self, parent)
self.setIcon(icon)
menu = QtWidgets.QMenu(parent)
#LEARNING MODE
menu_learning_action = menu.addAction("Learning mode")
menu_learning_action.setCheckable(True)
menu_learning_action.setChecked(learning_mode)
menu_learning_action.toggled.connect(self.main_app.set_learning_mode)
menu.addSeparator()
#EXIT
exitAction = menu.addAction("Exit")
exitAction.triggered.connect(self.exit_zero)
self.setContextMenu(menu)
示例9: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def __init__(self, view):
QObject.__init__(self, view)
self.view = view
self.model = QStandardItemModel()
self.view.setModel(self.model)
self.nodesets = []
self.server_mgr = None
self.view.header().setSectionResizeMode(1)
addNodeSetAction = QAction("Add Reference Node Set", self.model)
addNodeSetAction.triggered.connect(self.add_nodeset)
self.removeNodeSetAction = QAction("Remove Reference Node Set", self.model)
self.removeNodeSetAction.triggered.connect(self.remove_nodeset)
self.view.setContextMenuPolicy(Qt.CustomContextMenu)
self.view.customContextMenuRequested.connect(self.showContextMenu)
self._contextMenu = QMenu()
self._contextMenu.addAction(addNodeSetAction)
self._contextMenu.addAction(self.removeNodeSetAction)
示例10: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def __init__(self, view):
QObject.__init__(self, view)
self.view = view
self.model = QStandardItemModel()
self.view.setModel(self.model)
delegate = MyDelegate(self.view, self)
delegate.error.connect(self.error.emit)
self.view.setItemDelegate(delegate)
self.node = None
self.view.header().setSectionResizeMode(1)
self.addNamespaceAction = QAction("Add Namespace", self.model)
self.addNamespaceAction.triggered.connect(self.add_namespace)
self.removeNamespaceAction = QAction("Remove Namespace", self.model)
self.removeNamespaceAction.triggered.connect(self.remove_namespace)
self.view.setContextMenuPolicy(Qt.CustomContextMenu)
self.view.customContextMenuRequested.connect(self.showContextMenu)
self._contextMenu = QMenu()
self._contextMenu.addAction(self.addNamespaceAction)
self._contextMenu.addAction(self.removeNamespaceAction)
示例11: setup_context_menu_tree
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def setup_context_menu_tree(self):
self.ui.treeView.setContextMenuPolicy(Qt.CustomContextMenu)
self.ui.treeView.customContextMenuRequested.connect(self._show_context_menu_tree)
self._contextMenu = QMenu()
# tree view menu
self._contextMenu.addAction(self.ui.actionCopy)
self._contextMenu.addAction(self.ui.actionPaste)
self._contextMenu.addAction(self.ui.actionDelete)
self._contextMenu.addSeparator()
self._contextMenu.addAction(self.tree_ui.actionReload)
self._contextMenu.addSeparator()
self._contextMenu.addAction(self.ui.actionAddFolder)
self._contextMenu.addAction(self.ui.actionAddObject)
self._contextMenu.addAction(self.ui.actionAddVariable)
self._contextMenu.addAction(self.ui.actionAddProperty)
self._contextMenu.addAction(self.ui.actionAddMethod)
self._contextMenu.addAction(self.ui.actionAddObjectType)
self._contextMenu.addAction(self.ui.actionAddVariableType)
self._contextMenu.addAction(self.ui.actionAddDataType)
示例12: __init__
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def __init__(self, sandbox, *args, **kwargs):
QtWidgets.QMenu.__init__(self)
self.setTitle('Add Source')
self.sandbox = sandbox
backends = set(src.display_backend for src in __sources__)
for ibe, be in enumerate(backends):
self.addSection(be)
for src in [s for s in __sources__
if s.display_backend == be]:
self.addSourceDelegate(src)
if ibe is not len(backends) - 1:
self.addSeparator()
示例13: contextMenuEvent
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def contextMenuEvent(self, event):
menu = QtWidgets.QMenu(self)
hd = menu.addAction("Hide Search Table")
sideBar = menu.addAction("Show Sidebar")
history = menu.addAction("Show History")
action = menu.exec_(self.mapToGlobal(event.pos()))
if action == hd:
self.hide()
elif action == sideBar:
if ui.dockWidget_3.isHidden():
ui.dockWidget_3.show()
ui.btn1.setFocus()
else:
ui.dockWidget_3.hide()
ui.list1.setFocus()
elif action == history:
ui.setPreOpt()
示例14: _onSignatureTreeRightClicked
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def _onSignatureTreeRightClicked(self, position):
indexes = self.signature_tree.selectedIndexes()
if len(indexes) > 0:
level = 0
index = indexes[0]
while index.parent().isValid():
index = index.parent()
level += 1
editAction = self.cc.QAction("Edit pattern", self)
editAction.triggered.connect(self._onSignatureTreeEditPattern)
self.addAction(editAction)
printAction = self.cc.QAction("Print pattern path", self)
printAction.triggered.connect(self._onSignatureTreePrintPatternPath)
self.addAction(printAction)
menu = QMenu()
if level == 0:
menu.addAction(editAction)
menu.addAction(printAction)
menu.exec_(self.signature_tree.viewport().mapToGlobal(position))
示例15: _markerContextMenuEvent_
# 需要导入模块: from PyQt5 import QtWidgets [as 别名]
# 或者: from PyQt5.QtWidgets import QMenu [as 别名]
def _markerContextMenuEvent_(self, event):
menu = QtWidgets.QMenu(self.view)
self._fillMarkerContextMenu_(event, menu)
if self.labelItem and not self.labelAlwaysVisible:
@QtCore.pyqtSlot(bool)
def _toggleStickyLabel(value):
if self.uid != None:
settingPath = 'globalmapwidget/stickylabels2/'
if (value):
self.widget._app.settings.setValue(settingPath+self.uid, int(value))
else:
self.widget._app.settings.beginGroup(settingPath);
self.widget._app.settings.remove(self.uid);
self.widget._app.settings.endGroup();
self.setStickyLabel(value)
ftaction = menu.addAction('Sticky Label')
ftaction.toggled.connect(_toggleStickyLabel)
ftaction.setCheckable(True)
ftaction.setChecked(self.stickyLabel)
menu.exec(event.screenPos())