本文整理匯總了Python中qtpy.QtWidgets.QMenu方法的典型用法代碼示例。如果您正苦於以下問題:Python QtWidgets.QMenu方法的具體用法?Python QtWidgets.QMenu怎麽用?Python QtWidgets.QMenu使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QMenu方法的12個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_context_menu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def build_context_menu(self, index):
"""Build context menu for test item that given index points to."""
contextMenu = QMenu(self)
if self.isExpanded(index):
menuItem = create_action(self, _('Collapse'),
triggered=lambda: self.collapse(index))
else:
menuItem = create_action(self, _('Expand'),
triggered=lambda: self.expand(index))
menuItem.setEnabled(self.model().hasChildren(index))
contextMenu.addAction(menuItem)
menuItem = create_action(
self, _('Go to definition'),
triggered=lambda: self.go_to_test_definition(index))
test_location = self.model().data(index, Qt.UserRole)
menuItem.setEnabled(test_location[0] is not None)
contextMenu.addAction(menuItem)
return contextMenu
示例2: _context_menu_make
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def _context_menu_make(self, pos):
""" Reimplemented to return a custom context menu for images.
"""
format = self._control.cursorForPosition(pos).charFormat()
name = format.stringProperty(QtGui.QTextFormat.ImageName)
if name:
menu = QtWidgets.QMenu(self)
menu.addAction('Copy Image', lambda: self._copy_image(name))
menu.addAction('Save Image As...', lambda: self._save_image(name))
menu.addSeparator()
svg = self._name_to_svg_map.get(name, None)
if svg is not None:
menu.addSeparator()
menu.addAction('Copy SVG', lambda: svg_to_clipboard(svg))
menu.addAction('Save SVG As...',
lambda: save_svg(svg, self._control))
else:
menu = super(RichJupyterWidget, self)._context_menu_make(pos)
return menu
#---------------------------------------------------------------------------
# 'BaseFrontendMixin' abstract interface
#---------------------------------------------------------------------------
示例3: add_actions
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def add_actions(target, actions, insert_before=None):
"""Add actions to a menu"""
previous_action = None
target_actions = list(target.actions())
if target_actions:
previous_action = target_actions[-1]
if previous_action.isSeparator():
previous_action = None
for action in actions:
if (action is None) and (previous_action is not None):
if insert_before is None:
target.addSeparator()
else:
target.insertSeparator(insert_before)
elif isinstance(action, QMenu):
if insert_before is None:
target.addMenu(action)
else:
target.insertMenu(insert_before, action)
elif isinstance(action, QAction):
if insert_before is None:
target.addAction(action)
else:
target.insertAction(insert_before, action)
previous_action = action
示例4: build_menu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def build_menu(self):
self.file_menu = QtWidgets.QMenu('&File', self)
self.file_menu.addAction('&Open directory', self.open_directory, QtCore.Qt.CTRL + QtCore.Qt.Key_O)
self.file_menu.addAction('&Export image', self.export_image, QtCore.Qt.CTRL + QtCore.Qt.Key_S)
self.file_menu.addAction('&Quit', self.close, QtCore.Qt.CTRL + QtCore.Qt.Key_Q)
self.view_menu = QtWidgets.QMenu('&View', self)
self.view_menu.addAction('Zoom In', self.pix_label.increase_zoom, QtCore.Qt.CTRL + QtCore.Qt.Key_Plus)
self.view_menu.addAction('Zoom Out', self.pix_label.decrease_zoom, QtCore.Qt.CTRL + QtCore.Qt.Key_Minus)
self.view_menu.addAction('Zoom 1:1', self.pix_label.reset_zoom, QtCore.Qt.CTRL + QtCore.Qt.Key_0)
fullscreen = QtWidgets.QAction('&Full Screen', self)
fullscreen.setCheckable(True)
fullscreen.setShortcut(QtCore.Qt.Key_F11)
fullscreen.toggled.connect(self.toggle_full_screen)
self.view_menu.addAction(fullscreen)
self.tools_menu = QtWidgets.QMenu("&Tools", self)
self.tools_menu.addAction('&Show DICOM structure', self.show_structure, QtCore.Qt.Key_F2)
self.menuBar().addMenu(self.file_menu)
self.menuBar().addMenu(self.view_menu)
self.menuBar().addMenu(self.tools_menu)
示例5: contextMenuEvent
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def contextMenuEvent(self, event):
"""Override Qt method."""
copy_action = create_action(
self, _("Copy text"), icon=ima.icon('editcopy'),
triggered=self.copy,
shortcut=self.CONF.get_shortcut(CONF_SECTION, 'copy'))
paste_action = create_action(
self, _("Paste text"),
icon=ima.icon('editpaste'),
triggered=self.paste,
shortcut=self.CONF.get_shortcut(CONF_SECTION, 'paste'))
clear_action = create_action(
self, _("Clear Terminal"),
triggered=self.clear,
shortcut=self.CONF.get_shortcut(CONF_SECTION, 'clear'))
zoom_in = create_action(
self, _("Zoom in"), triggered=self.increase_font,
shortcut=self.CONF.get_shortcut(CONF_SECTION, 'zoom in'))
zoom_out = create_action(
self, _("Zoom out"), triggered=self.decrease_font,
shortcut=self.CONF.get_shortcut(CONF_SECTION, 'zoom out'))
menu = QMenu(self)
actions = [self.pageAction(QWebEnginePage.SelectAll),
copy_action, paste_action, clear_action, None, zoom_in,
zoom_out]
add_actions(menu, actions)
menu.popup(event.globalPos())
event.accept()
示例6: openWidgetMenu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def openWidgetMenu(self,position):
indexes = self.ui.treeWidget_2.selectedIndexes()
item = self.ui.treeWidget_2.itemAt(position)
if item == None:
return
#item = self.ui.listWidget.itemAt(position)
if len(indexes) > 0:
menu = QMenu()
menu.addAction(QAction("Delete", menu,checkable = True))#This function is perhaps useless
#menu.triggered.connect(self.eraseItem)
item = self.ui.treeWidget_2.itemAt(position)
#collec = str(item.text())
menu.triggered.connect(lambda action: self.ListMethodSelected(action, item))
menu.exec_(self.ui.treeWidget_2.viewport().mapToGlobal(position))
示例7: _context_menu_make
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def _context_menu_make(self, pos):
""" Creates a context menu for the given QPoint (in widget coordinates).
"""
menu = QtWidgets.QMenu(self)
self.cut_action = menu.addAction('Cut', self.cut)
self.cut_action.setEnabled(self.can_cut())
self.cut_action.setShortcut(QtGui.QKeySequence.Cut)
self.copy_action = menu.addAction('Copy', self.copy)
self.copy_action.setEnabled(self.can_copy())
self.copy_action.setShortcut(QtGui.QKeySequence.Copy)
self.paste_action = menu.addAction('Paste', self.paste)
self.paste_action.setEnabled(self.can_paste())
self.paste_action.setShortcut(QtGui.QKeySequence.Paste)
anchor = self._control.anchorAt(pos)
if anchor:
menu.addSeparator()
self.copy_link_action = menu.addAction(
'Copy Link Address', lambda: self.copy_anchor(anchor=anchor))
self.open_link_action = menu.addAction(
'Open Link', lambda: self.open_anchor(anchor=anchor))
menu.addSeparator()
menu.addAction(self.select_all_action)
menu.addSeparator()
menu.addAction(self.export_action)
menu.addAction(self.print_action)
return menu
示例8: get_menu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def get_menu(self):
menu = QtWidgets.QMenu(self)
self.actions = []
for state in self.module.states:
action = QtWidgets.QAction(state, self)
self.actions.append(action)
action.triggered.connect(functools.partial(self.func, state))
menu.addAction(action)
return menu
示例9: contextMenuEvent
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def contextMenuEvent(self, event):
for widget in self.module_widgets:
if widget.geometry().contains(event.pos()):
if widget.module.owner is not None:
act = QtWidgets.QAction('Free %s'%widget.module.name, self)
act.triggered.connect(widget.module.free)
menu = QtWidgets.QMenu()
menu.addAction(act)
menu.exec_(event.globalPos())
示例10: openMenu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def openMenu(self,position):
indexes = self.ui.treeWidget.selectedIndexes()
item = self.ui.treeWidget.itemAt(position)
db_origin = ""
#if item.parent():
# db_origin = item.parent().text(0)
collec = item.text(0)
if len(indexes) > 0:
level = 0
index = indexes[0]
while index.parent().isValid():
index = index.parent()
level = level + 1
menu = QMenu()
#print((collec, db_origin))
if level ==0:
pass
else:
#keyarray = GetKeys(collec, db_origin)
#if "Open" in keyarray:
if self.ui.combobox.currentText()==u"K線":
menu.addAction(QAction("Kline", menu, checkable=True))
menu.addAction(QAction("Open", menu, checkable=True))
menu.addAction(QAction("Close", menu, checkable=True))#open up different menu with different kind of graphs
menu.addAction(QAction("High", menu, checkable=True))
menu.addAction(QAction("Low", menu, checkable=True))
menu.addAction(QAction("Volume", menu, checkable=True))
#menu.addAction(QAction("P_change", menu, checkable=True))
#menu.addAction(QAction("Turnover",menu,checkable=True))
if self.ui.combobox.currentText()==u"複權":
menu.addAction(QAction("Kline", menu, checkable=True))
menu.addAction(QAction("Open", menu, checkable=True))
menu.addAction(QAction("Close", menu, checkable=True))
menu.addAction(QAction("High", menu, checkable=True))
menu.addAction(QAction("Low", menu, checkable=True))
menu.addAction(QAction("Volume", menu, checkable=True))
menu.addAction(QAction("Amount", menu, checkable=True))
if self.ui.combobox.currentText()==u"分筆數據":
menu.addAction(QAction("分筆", menu, checkable=True))
if self.ui.combobox.currentText()==u"曆史分鍾":
menu.addAction(QAction("Kline", menu, checkable=True))
menu.addAction(QAction("Open", menu, checkable=True))
menu.addAction(QAction("Close", menu, checkable=True))
menu.addAction(QAction("High", menu, checkable=True))
menu.addAction(QAction("Low", menu, checkable=True))
menu.addAction(QAction("Volume", menu, checkable=True))
menu.addAction(QAction("Amount", menu, checkable=True))
if self.ui.combobox.currentText()==u"十大股東":
menu.addAction(QAction("季度餅圖", menu, checkable=True))
#menu.addAction(QAction("持股比例", menu, checkable=True))
#for g in keyarray:
#menu.addAction(QAction(g, menu, checkable=True))
menu.triggered.connect(lambda action: self.methodSelected(action, collec))
menu.exec_(self.ui.treeWidget.viewport().mapToGlobal(position))
示例11: openMenu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def openMenu(self,position):
indexes = self.ui.treeWidget.selectedIndexes()
item = self.ui.treeWidget.itemAt(position)
db_origin = ""
#if item.parent():
# db_origin = item.parent().text(0)
collec = str(item.text(0).encode("utf-8"))
if len(indexes) > 0:
level = 0
index = indexes[0]
while index.parent().isValid():
index = index.parent()
level = level + 1
menu = QMenu()
#print((collec, db_origin))
if level ==0:
pass
else:
#keyarray = GetKeys(collec, db_origin)
#if "Open" in keyarray:
if self.ui.combobox.currentText()==u"K線":
menu.addAction(QAction("Kline", menu, checkable=True))
menu.addAction(QAction("Open", menu, checkable=True))
menu.addAction(QAction("Close", menu, checkable=True))#open up different menu with different kind of graphs
menu.addAction(QAction("High", menu, checkable=True))
menu.addAction(QAction("Low", menu, checkable=True))
menu.addAction(QAction("Volume", menu, checkable=True))
#menu.addAction(QAction("P_change", menu, checkable=True))
#menu.addAction(QAction("Turnover",menu,checkable=True))
if self.ui.combobox.currentText()==u"複權":
menu.addAction(QAction("Kline", menu, checkable=True))
menu.addAction(QAction("Open", menu, checkable=True))
menu.addAction(QAction("Close", menu, checkable=True))
menu.addAction(QAction("High", menu, checkable=True))
menu.addAction(QAction("Low", menu, checkable=True))
menu.addAction(QAction("Volume", menu, checkable=True))
menu.addAction(QAction("Amount", menu, checkable=True))
if self.ui.combobox.currentText()==u"分筆數據":
menu.addAction(QAction("分筆", menu, checkable=True))
if self.ui.combobox.currentText()==u"曆史分鍾":
menu.addAction(QAction("Kline", menu, checkable=True))
menu.addAction(QAction("Open", menu, checkable=True))
menu.addAction(QAction("Close", menu, checkable=True))
menu.addAction(QAction("High", menu, checkable=True))
menu.addAction(QAction("Low", menu, checkable=True))
menu.addAction(QAction("Volume", menu, checkable=True))
menu.addAction(QAction("Amount", menu, checkable=True))
if self.ui.combobox.currentText()==u"十大股東":
menu.addAction(QAction("季度餅圖", menu, checkable=True))
#menu.addAction(QAction("持股比例", menu, checkable=True))
#for g in keyarray:
#menu.addAction(QAction(g, menu, checkable=True))
menu.triggered.connect(lambda action: self.methodSelected(action, collec))
menu.exec_(self.ui.treeWidget.viewport().mapToGlobal(position))
示例12: setup_window
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QMenu [as 別名]
def setup_window(self):
""" """
self.close_action = create_action(self, _("&Quit"),
triggered=self.close)
self.file_menu_actions.append(self.close_action)
self.file_menu = self.menuBar().addMenu(_("&File"))
add_actions(self.file_menu, self.file_menu_actions)
# Environments
self.add_env_action = create_action(self, _("&Add"),
triggered=self.add_env)
self.clone_env_action = create_action(self, _("&Clone"),
triggered=self.clone_env)
self.remove_env_action = create_action(self, _("&Remove"),
triggered=self.remove_env)
self.envs_list_menu = QMenu(_('Environments'))
self.envs_menu_actions = [self.add_env_action, self.clone_env_action,
self.remove_env_action, None,
self.envs_list_menu]
self.envs_menu = self.menuBar().addMenu(_("&Environments"))
add_actions(self.envs_menu, self.envs_menu_actions)
self.update_env_menu()
# Channels
self.envs_menu = self.menuBar().addMenu(_("&Channels"))
# Tools
self.preferences_action = create_action(self,
_("&Preferences"),
triggered=self.preferences)
self.tools_menu_actions.append(self.preferences_action)
self.tools_menu = self.menuBar().addMenu(_("&Tools"))
add_actions(self.tools_menu, self.tools_menu_actions)
# Help
self.report_action = create_action(self,
_("&Report issue"),
triggered=self.report_issue)
self.about_action = create_action(self, _("&About"),
triggered=self.about)
self.help_menu_actions.append(self.report_action)
self.help_menu_actions.append(self.about_action)
self.help_menu = self.menuBar().addMenu(_("&Help"))
add_actions(self.help_menu, self.help_menu_actions)
self.setWindowIcon(get_icon('condapackages.png'))