本文整理匯總了Python中qtpy.QtWidgets.QAction方法的典型用法代碼示例。如果您正苦於以下問題:Python QtWidgets.QAction方法的具體用法?Python QtWidgets.QAction怎麽用?Python QtWidgets.QAction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類qtpy.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QAction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: build_menu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [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)
示例2: __enable_point_context
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def __enable_point_context(self) -> None:
"""Adjust the status of QActions.
What ever we have least one point or not,
need to enable / disable QAction.
"""
selection = self.entities_point.selected_rows()
# Set grounded state
if selection:
self.action_p_lock.setChecked(all(
VLink.FRAME in self.vpoint_list[row].links for row in selection
))
self.context.point_enable(len(selection))
def mj_func(order: int) -> Callable[[], None]:
"""Generate a merge function."""
@Slot()
def func() -> None:
self.__to_multiple_joint(order, selection)
return func
for i, p in enumerate(selection):
action = QAction(f"Base on Point{p}", self)
action.triggered.connect(mj_func(i))
self.pop_point_m.addAction(action)
示例3: __enable_link_context
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def __enable_link_context(self) -> None:
"""Enable / disable link's QAction, same as point table."""
selection = self.entities_link.selected_rows()
row = self.entities_link.currentRow()
self.context.link_enable(len(selection), row)
def ml_func(order: int) -> Callable[[], None]:
"""Generate a merge function."""
@Slot(int)
def func() -> None:
self.__merge_link(order, selection)
return func
for i, row in enumerate(selection):
action = QAction(f"Base on \"{self.vlink_list[row].name}\"", self)
action.triggered.connect(ml_func(i))
self.pop_link_m.addAction(action)
示例4: add_dock_widget
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def add_dock_widget(self, create_widget, name):
dock_widget = MyDockWidget(create_widget,
name + ' (%s)' % self.parent.name)
self.dock_widgets[name] = dock_widget
self.addDockWidget(QtCore.Qt.TopDockWidgetArea,
dock_widget)
if self.last_docked is not None:
self.tabifyDockWidget(self.last_docked, dock_widget)
# put tabs on top
self.setTabPosition(dock_widget.allowedAreas(),
QtWidgets.QTabWidget.North)
self.last_docked = dock_widget
self.last_docked.hide() # by default no widget is created...
action = QtWidgets.QAction(name, self.menu_modules)
action.setCheckable(True)
self.module_actions.append(action)
self.menu_modules.addAction(action)
# make sure menu and widget are in sync
action.changed.connect(lambda: dock_widget.setVisible(action.isChecked()))
dock_widget.visibilityChanged.connect(lambda:action.setChecked(dock_widget.isVisible()))
dock_widget.visibilityChanged.connect(self.hide_centralbutton)
self.set_background_color(dock_widget)
示例5: add_actions
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [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
示例6: openWidgetMenu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [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: _add_start
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def _add_start(self):
"""Add Start Recording action.
"""
start = QAction('Start Recording...', self.main_window._qt_window)
start.setShortcut('Alt+T')
start.setStatusTip('Start recording a trace file')
start.triggered.connect(self._start_trace)
self.sub_menu.addAction(start)
return start
示例8: _add_stop
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def _add_stop(self):
"""Add Stop Recording action.
"""
stop = QAction('Stop Recording', self.main_window._qt_window)
stop.setShortcut('Shift+Alt+T')
stop.setStatusTip('Stop recording a trace file')
stop.triggered.connect(self._stop_trace)
self.sub_menu.addAction(stop)
return stop
示例9: init_kernel_menu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def init_kernel_menu(self):
self.kernel_menu = self.menuBar().addMenu("&Kernel")
# Qt on OSX maps Ctrl to Cmd, and Meta to Ctrl
# keep the signal shortcuts to ctrl, rather than
# platform-default like we do elsewhere.
ctrl = "Meta" if sys.platform == 'darwin' else "Ctrl"
self.interrupt_kernel_action = QtWidgets.QAction("&Interrupt current Kernel",
self,
triggered=self.interrupt_kernel_active_frontend,
shortcut=ctrl+"+C",
)
self.add_menu_action(self.kernel_menu, self.interrupt_kernel_action)
self.restart_kernel_action = QtWidgets.QAction("&Restart current Kernel",
self,
triggered=self.restart_kernel_active_frontend,
shortcut=ctrl+"+.",
)
self.add_menu_action(self.kernel_menu, self.restart_kernel_action)
self.kernel_menu.addSeparator()
self.confirm_restart_kernel_action = QtWidgets.QAction("&Confirm kernel restart",
self,
checkable=True,
checked=self.active_frontend.confirm_restart,
triggered=self.toggle_confirm_restart_active_frontend
)
self.add_menu_action(self.kernel_menu, self.confirm_restart_kernel_action)
self.tab_widget.currentChanged.connect(self.update_restart_checkbox)
示例10: init_help_menu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def init_help_menu(self):
# please keep the Help menu in Mac Os even if empty. It will
# automatically contain a search field to search inside menus and
# please keep it spelled in English, as long as Qt Doesn't support
# a QAction.MenuRole like HelpMenuRole otherwise it will lose
# this search field functionality
self.help_menu = self.menuBar().addMenu("&Help")
# Help Menu
self.help_action = QtWidgets.QAction("Show &QtConsole help", self,
triggered=self._show_help)
self.online_help_action = QtWidgets.QAction("Open online &help", self,
triggered=self._open_online_help)
self.add_menu_action(self.help_menu, self.help_action)
self.add_menu_action(self.help_menu, self.online_help_action)
示例11: get_menu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [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
示例12: contextMenuEvent
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [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())
示例13: action2button
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def action2button(action, autoraise=True, text_beside_icon=False, parent=None):
"""Create a QToolButton directly from a QAction object"""
if parent is None:
parent = action.parent()
button = QToolButton(parent)
button.setDefaultAction(action)
button.setAutoRaise(autoraise)
if text_beside_icon:
button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
return button
示例14: create_action
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [as 別名]
def create_action(parent, text, shortcut=None, icon=None, tip=None,
toggled=None, triggered=None, data=None, menurole=None,
context=Qt.WindowShortcut):
"""Create a QAction"""
action = QAction(text, parent)
if triggered is not None:
action.triggered.connect(triggered)
if toggled is not None:
action.toggled.connect(toggled)
action.setCheckable(True)
if icon is not None:
action.setIcon(icon)
if shortcut is not None:
action.setShortcut(shortcut)
if tip is not None:
action.setToolTip(tip)
action.setStatusTip(tip)
if data is not None:
action.setData(to_qvariant(data))
if menurole is not None:
action.setMenuRole(menurole)
#TODO: Hard-code all shortcuts and choose context=Qt.WidgetShortcut
# (this will avoid calling shortcuts from another dockwidget
# since the context thing doesn't work quite well with these widgets)
action.setShortcutContext(context)
return action
示例15: openMenu
# 需要導入模塊: from qtpy import QtWidgets [as 別名]
# 或者: from qtpy.QtWidgets import QAction [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))