本文整理汇总了Python中AnyQt.QtWidgets.QAction类的典型用法代码示例。如果您正苦于以下问题:Python QAction类的具体用法?Python QAction怎么用?Python QAction使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QAction类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: zoom_actions
def zoom_actions(self, parent):
def zoom(s):
"""
Zoom in/out by factor `s`.
scaleBy scales the view's bounds (the axis range)
"""
self.view_box.scaleBy((1 / s, 1 / s))
def fit_to_view():
self.viewbox.autoRange()
zoom_in = QAction(
"Zoom in", parent, triggered=lambda: zoom(1.25)
)
zoom_in.setShortcuts([QKeySequence(QKeySequence.ZoomIn),
QKeySequence(parent.tr("Ctrl+="))])
zoom_out = QAction(
"Zoom out", parent, shortcut=QKeySequence.ZoomOut,
triggered=lambda: zoom(1 / 1.25)
)
zoom_fit = QAction(
"Fit in view", parent,
shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0),
triggered=fit_to_view
)
parent.addActions([zoom_in, zoom_out, zoom_fit])
示例2: __init__
def __init__(self, *args):
super().__init__(*args)
self.setAlignment(Qt.AlignTop | Qt.AlignLeft)
self.__backgroundIcon = QIcon()
self.__autoScroll = False
self.__autoScrollMargin = 16
self.__autoScrollTimer = QTimer(self)
self.__autoScrollTimer.timeout.connect(self.__autoScrollAdvance)
# scale factor accumulating partial increments from wheel events
self.__zoomLevel = 100
# effective scale level(rounded to whole integers)
self.__effectiveZoomLevel = 100
self.__zoomInAction = QAction(
self.tr("Zoom in"), self, objectName="action-zoom-in",
shortcut=QKeySequence.ZoomIn,
triggered=self.zoomIn,
)
self.__zoomOutAction = QAction(
self.tr("Zoom out"), self, objectName="action-zoom-out",
shortcut=QKeySequence.ZoomOut,
triggered=self.zoomOut
)
self.__zoomResetAction = QAction(
self.tr("Reset Zoom"), self, objectName="action-zoom-reset",
triggered=self.zoomReset,
shortcut=QKeySequence(Qt.ControlModifier | Qt.Key_0)
)
示例3: createActionForItem
def createActionForItem(self, item):
"""Create the QAction instance for item.
"""
action = QAction(item.icon(), item.text(), self,
toolTip=item.toolTip())
action.setData(item)
return action
示例4: createActionForItem
def createActionForItem(self, index):
"""Create the QAction instance for item at `index` (`QModelIndex`).
"""
action = QAction(
item_icon(index), item_text(index), self,
toolTip=item_tooltip(index)
)
action.setData(QPersistentModelIndex(index))
return action
示例5: _setup_gui_labels
def _setup_gui_labels(self):
vlayout = QVBoxLayout()
vlayout.setContentsMargins(0, 0, 0, 0)
vlayout.setSpacing(1)
self.labels_edit = QTreeView()
self.labels_edit.setEditTriggers(QTreeView.CurrentChanged)
self.labels_edit.setRootIsDecorated(False)
self.labels_model = DictItemsModel()
self.labels_edit.setModel(self.labels_model)
self.labels_edit.selectionModel().selectionChanged.connect(
self.on_label_selection_changed)
# Necessary signals to know when the labels change
self.labels_model.dataChanged.connect(self.on_labels_changed)
self.labels_model.rowsInserted.connect(self.on_labels_changed)
self.labels_model.rowsRemoved.connect(self.on_labels_changed)
vlayout.addWidget(self.labels_edit)
hlayout = QHBoxLayout()
hlayout.setContentsMargins(0, 0, 0, 0)
hlayout.setSpacing(1)
self.add_label_action = QAction(
"+", self,
toolTip="Add a new label.",
triggered=self.on_add_label,
enabled=False,
shortcut=QKeySequence(QKeySequence.New))
self.remove_label_action = QAction(
unicodedata.lookup("MINUS SIGN"), self,
toolTip="Remove selected label.",
triggered=self.on_remove_label,
enabled=False,
shortcut=QKeySequence(QKeySequence.Delete))
button_size = gui.toolButtonSizeHint()
button_size = QSize(button_size, button_size)
button = QToolButton(self)
button.setFixedSize(button_size)
button.setDefaultAction(self.add_label_action)
hlayout.addWidget(button)
button = QToolButton(self)
button.setFixedSize(button_size)
button.setDefaultAction(self.remove_label_action)
hlayout.addWidget(button)
hlayout.addStretch(10)
vlayout.addLayout(hlayout)
self.main_form.addRow("Labels:", vlayout)
示例6: __insertItem
def __insertItem(self, index, item):
"""
Insert a widget action (from a `QStandardItem`) at index.
"""
value = item.data(self.__actionRole)
if value is not None:
action = value
else:
action = QAction(item.text(), self)
action.setIcon(item.icon())
self.insertAction(index, action)
示例7: __insertItem
def __insertItem(self, index, item):
"""
Insert a widget action from `item` (`QModelIndex`) at `index`.
"""
value = item.data(self.__actionRole)
if isinstance(value, QAction):
action = value
else:
action = QAction(item_text(item), self)
action.setIcon(item_icon(item))
action.setToolTip(item_tooltip(item))
self.insertAction(index, action)
示例8: __init__
def __init__(self, plot, icon_name=None, attr_name='', attr_value=None, callback=None, parent=None):
QAction.__init__(self, parent)
if type(callback) == str:
callback = getattr(plot, callback, None)
if callback:
self.triggered.connect(callback)
if attr_name:
self._plot = plot
self.attr_name = attr_name
self.attr_value = attr_value
self.triggered.connect(self.set_attribute)
if icon_name:
self.setIcon(
QIcon(os.path.join(os.path.dirname(__file__),
"../../icons", icon_name + '.png')))
self.setIconVisibleInMenu(True)
示例9: createTabButton
def createTabButton(self, widget, text, icon=None, toolTip=None):
"""
Create the tab button for `widget`.
"""
action = QAction(text, self)
action.setCheckable(True)
if icon:
action.setIcon(icon)
if toolTip:
action.setToolTip(toolTip)
self.__tabActionGroup.addAction(action)
self.__actionMapper.setMapping(action, action)
action.toggled.connect(self.__actionMapper.map)
button = ToolBoxTabButton(self, objectName="toolbox-tab-button")
button.setDefaultAction(action)
button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
button.setSizePolicy(QSizePolicy.Ignored,
QSizePolicy.Fixed)
if self.__tabIconSize.isValid():
button.setIconSize(self.__tabIconSize)
if self.__tabButtonHeight > 0:
button.setFixedHeight(self.__tabButtonHeight)
return button
示例10: add_zoom_actions
def add_zoom_actions(self, menu):
zoom_in = QAction(
"Zoom in", self, triggered=self.plot.vb.set_mode_zooming
)
zoom_in.setShortcuts([Qt.Key_Z, QKeySequence(QKeySequence.ZoomIn)])
zoom_in.setShortcutContext(Qt.WidgetWithChildrenShortcut)
self.addAction(zoom_in)
if menu:
menu.addAction(zoom_in)
zoom_fit = QAction(
"Zoom to fit", self,
triggered=lambda x: (self.plot.vb.autoRange(), self.plot.vb.set_mode_panning())
)
zoom_fit.setShortcuts([Qt.Key_Backspace, QKeySequence(Qt.ControlModifier | Qt.Key_0)])
zoom_fit.setShortcutContext(Qt.WidgetWithChildrenShortcut)
self.addAction(zoom_fit)
if menu:
menu.addAction(zoom_fit)
示例11: __init__
def __init__(self, parent=None):
QObject.__init__(self, parent)
self.__splitter = None
self.__widget = None
self.__updateOnShow = True # Need __update on next show event
self.__animationEnabled = True
self.__size = -1
self.__expanded = False
self.__animation = QPropertyAnimation(self, b"size_", self, duration=200)
self.__action = QAction("toogle-expanded", self, checkable=True)
self.__action.triggered[bool].connect(self.setExpanded)
示例12: __init__
def __init__(self, parent, plot):
super().__init__(parent, plot)
self._item = None
self._start_pos = None
self._selection_rect = None
self._mouse_dragging = False
self._delete_action = QAction(
"Delete", self, shortcutContext=Qt.WindowShortcut
)
self._delete_action.setShortcuts([QKeySequence.Delete,
QKeySequence("Backspace")])
self._delete_action.triggered.connect(self.delete)
示例13: test_lineedit
def test_lineedit(self):
"""test LineEdit
"""
line = LineEdit()
line.show()
action1 = QAction(QIcon(line.style().standardPixmap(
QStyle.SP_ArrowBack)
),
"Search", line)
menu = QMenu()
menu.addAction("Regex")
menu.addAction("Wildcard")
action1.setMenu(menu)
line.setAction(action1, LineEdit.LeftPosition)
self.assertIs(line.actionAt(LineEdit.LeftPosition), action1)
self.assertTrue(line.button(LineEdit.LeftPosition) is not None)
self.assertTrue(line.button(LineEdit.RightPosition) is None)
with self.assertRaises(ValueError):
line.removeActionAt(100)
line.removeActionAt(LineEdit.LeftPosition)
self.assertIs(line.actionAt(LineEdit.LeftPosition), None)
line.setAction(action1, LineEdit.LeftPosition)
action2 = QAction(QIcon(line.style().standardPixmap(
QStyle.SP_TitleBarCloseButton)),
"Delete", line)
line.setAction(action2, LineEdit.RightPosition)
line.setPlaceholderText("Search")
self.assertEqual(line.placeholderText(), "Search")
b = line.button(LineEdit.RightPosition)
b.setFlat(False)
self.app.exec_()
示例14: addTab
def addTab(self, widget, text, toolTip=None, icon=None):
if self.__macUnified:
action = QAction(text, self)
if toolTip:
action.setToolTip(toolTip)
if icon:
action.setIcon(toolTip)
action.setData(len(self.tab.actions()))
self.tab.addAction(action)
self.stack.addWidget(widget)
else:
i = self.tab.addTab(widget, text)
if toolTip:
self.tab.setTabToolTip(i, toolTip)
if icon:
self.tab.setTabIcon(i, icon)
示例15: __init__
def __init__(self, parent=None, widget=None, title=None, **kwargs):
super().__init__(parent, **kwargs)
self.setFeatures(QDockWidget.DockWidgetClosable)
self.setAllowedAreas(Qt.NoDockWidgetArea)
self.__title = ""
self.__icon = ""
self.__focusframe = None
self.__deleteaction = QAction(
"Remove", self, shortcut=QKeySequence.Delete,
enabled=False, triggered=self.closeRequested
)
self.addAction(self.__deleteaction)
if widget is not None:
self.setWidget(widget)
self.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
if title:
self.setTitle(title)
self.setFocusPolicy(Qt.ClickFocus | Qt.TabFocus)