本文整理汇总了Python中AnyQt.QtWidgets.QToolButton.setDefaultAction方法的典型用法代码示例。如果您正苦于以下问题:Python QToolButton.setDefaultAction方法的具体用法?Python QToolButton.setDefaultAction怎么用?Python QToolButton.setDefaultAction使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QToolButton
的用法示例。
在下文中一共展示了QToolButton.setDefaultAction方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: actionButton
# 需要导入模块: from AnyQt.QtWidgets import QToolButton [as 别名]
# 或者: from AnyQt.QtWidgets.QToolButton import setDefaultAction [as 别名]
def actionButton(self, action):
if isinstance(action, QAction):
button = QToolButton(self)
button.setDefaultAction(action)
return button
elif isinstance(action, QAbstractButton):
return action
示例2: _setup_gui_labels
# 需要导入模块: from AnyQt.QtWidgets import QToolButton [as 别名]
# 或者: from AnyQt.QtWidgets.QToolButton import setDefaultAction [as 别名]
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)
示例3: SortedListWidget
# 需要导入模块: from AnyQt.QtWidgets import QToolButton [as 别名]
# 或者: from AnyQt.QtWidgets.QToolButton import setDefaultAction [as 别名]
class SortedListWidget(QWidget):
sortingOrderChanged = Signal()
class _MyItemDelegate(QStyledItemDelegate):
def __init__(self, sortingModel, parent):
QStyledItemDelegate.__init__(self, parent)
self.sortingModel = sortingModel
def sizeHint(self, option, index):
size = QStyledItemDelegate.sizeHint(self, option, index)
return QSize(size.width(), size.height() + 4)
def createEditor(self, parent, option, index):
cb = QComboBox(parent)
cb.setModel(self.sortingModel)
cb.showPopup()
return cb
def setEditorData(self, editor, index):
pass # TODO: sensible default
def setModelData(self, editor, model, index):
text = editor.currentText()
model.setData(index, text)
def __init__(self, *args):
QWidget.__init__(self, *args)
self.setContentsMargins(0, 0, 0, 0)
gridLayout = QGridLayout()
gridLayout.setContentsMargins(0, 0, 0, 0)
gridLayout.setSpacing(1)
model = QStandardItemModel(self)
model.rowsInserted.connect(self.__changed)
model.rowsRemoved.connect(self.__changed)
model.dataChanged.connect(self.__changed)
self._listView = QListView(self)
self._listView.setModel(model)
# self._listView.setDragEnabled(True)
self._listView.setDropIndicatorShown(True)
self._listView.setDragDropMode(QListView.InternalMove)
self._listView.viewport().setAcceptDrops(True)
self._listView.setMinimumHeight(100)
gridLayout.addWidget(self._listView, 0, 0, 2, 2)
vButtonLayout = QVBoxLayout()
self._upAction = QAction(
"\u2191", self, toolTip="Move up")
self._upButton = QToolButton(self)
self._upButton.setDefaultAction(self._upAction)
self._upButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
self._downAction = QAction(
"\u2193", self, toolTip="Move down")
self._downButton = QToolButton(self)
self._downButton.setDefaultAction(self._downAction)
self._downButton.setSizePolicy(
QSizePolicy.Fixed, QSizePolicy.MinimumExpanding)
vButtonLayout.addWidget(self._upButton)
vButtonLayout.addWidget(self._downButton)
gridLayout.addLayout(vButtonLayout, 0, 2, 2, 1)
hButtonLayout = QHBoxLayout()
self._addAction = QAction("+", self)
self._addButton = QToolButton(self)
self._addButton.setDefaultAction(self._addAction)
self._removeAction = QAction("-", self)
self._removeButton = QToolButton(self)
self._removeButton.setDefaultAction(self._removeAction)
hButtonLayout.addWidget(self._addButton)
hButtonLayout.addWidget(self._removeButton)
hButtonLayout.addStretch(10)
gridLayout.addLayout(hButtonLayout, 2, 0, 1, 2)
self.setLayout(gridLayout)
self._addAction.triggered.connect(self._onAddAction)
self._removeAction.triggered.connect(self._onRemoveAction)
self._upAction.triggered.connect(self._onUpAction)
self._downAction.triggered.connect(self._onDownAction)
def sizeHint(self):
size = QWidget.sizeHint(self)
return QSize(size.width(), 100)
def _onAddAction(self):
item = QStandardItem("")
item.setFlags(item.flags() ^ Qt.ItemIsDropEnabled)
self._listView.model().appendRow(item)
self._listView.setCurrentIndex(item.index())
#.........这里部分代码省略.........
示例4: SelectionSetsWidget
# 需要导入模块: from AnyQt.QtWidgets import QToolButton [as 别名]
# 或者: from AnyQt.QtWidgets.QToolButton import setDefaultAction [as 别名]
class SelectionSetsWidget(QFrame):
"""
Widget for managing multiple stored item selections
"""
selectionModified = Signal(bool)
def __init__(self, parent):
QFrame.__init__(self, parent)
self.setContentsMargins(0, 0, 0, 0)
layout = QVBoxLayout()
layout.setContentsMargins(0, 0, 0, 0)
layout.setSpacing(1)
self._setNameLineEdit = QLineEdit(self)
layout.addWidget(self._setNameLineEdit)
self._setListView = QListView(self)
self._listModel = QStandardItemModel(self)
self._proxyModel = QSortFilterProxyModel(self)
self._proxyModel.setSourceModel(self._listModel)
self._setListView.setModel(self._proxyModel)
self._setListView.setItemDelegate(ListItemDelegate(self))
self._setNameLineEdit.textChanged.connect(
self._proxyModel.setFilterFixedString)
self._completer = QCompleter(self._listModel, self)
self._setNameLineEdit.setCompleter(self._completer)
self._listModel.itemChanged.connect(self._onSetNameChange)
layout.addWidget(self._setListView)
buttonLayout = QHBoxLayout()
self._addAction = QAction(
"+", self, toolTip="Add a new sort key")
self._updateAction = QAction(
"Update", self, toolTip="Update/save current selection")
self._removeAction = QAction(
"\u2212", self, toolTip="Remove selected sort key.")
self._addToolButton = QToolButton(self)
self._updateToolButton = QToolButton(self)
self._removeToolButton = QToolButton(self)
self._updateToolButton.setSizePolicy(
QSizePolicy.MinimumExpanding, QSizePolicy.Minimum)
self._addToolButton.setDefaultAction(self._addAction)
self._updateToolButton.setDefaultAction(self._updateAction)
self._removeToolButton.setDefaultAction(self._removeAction)
buttonLayout.addWidget(self._addToolButton)
buttonLayout.addWidget(self._updateToolButton)
buttonLayout.addWidget(self._removeToolButton)
layout.addLayout(buttonLayout)
self.setLayout(layout)
self._addAction.triggered.connect(self.addCurrentSelection)
self._updateAction.triggered.connect(self.updateSelectedSelection)
self._removeAction.triggered.connect(self.removeSelectedSelection)
self._setListView.selectionModel().selectionChanged.connect(
self._onListViewSelectionChanged)
self.selectionModel = None
self._selections = []
def sizeHint(self):
size = QFrame.sizeHint(self)
return QSize(size.width(), 150)
def _onSelectionChanged(self, selected, deselected):
self.setSelectionModified(True)
def _onListViewSelectionChanged(self, selected, deselected):
try:
index = self._setListView.selectedIndexes()[0]
except IndexError:
return
self.commitSelection(self._proxyModel.mapToSource(index).row())
def _onSetNameChange(self, item):
self.selections[item.row()].name = str(item.text())
def _setButtonStates(self, val):
self._updateToolButton.setEnabled(val)
def setSelectionModel(self, selectionModel):
if self.selectionModel:
self.selectionModel.selectionChanged.disconnect(
self._onSelectionChanged)
self.selectionModel = selectionModel
self.selectionModel.selectionChanged.connect(self._onSelectionChanged)
def addCurrentSelection(self):
item = self.addSelection(
SelectionByKey(self.selectionModel.selection(),
name="New selection",
key=(1, 2, 3, 10)))
index = self._proxyModel.mapFromSource(item.index())
#.........这里部分代码省略.........
示例5: _init_ui
# 需要导入模块: from AnyQt.QtWidgets import QToolButton [as 别名]
# 或者: from AnyQt.QtWidgets.QToolButton import setDefaultAction [as 别名]
def _init_ui(self):
namesBox = gui.vBox(self.controlArea, "Names")
hbox = gui.hBox(namesBox, margin=0, spacing=0)
gui.lineEdit(hbox, self, "attr1", "Variable X: ",
controlWidth=80, orientation=Qt.Horizontal,
callback=self._attr_name_changed)
gui.separator(hbox, 21)
hbox = gui.hBox(namesBox, margin=0, spacing=0)
attr2 = gui.lineEdit(hbox, self, "attr2", "Variable Y: ",
controlWidth=80, orientation=Qt.Horizontal,
callback=self._attr_name_changed)
gui.separator(hbox)
gui.checkBox(hbox, self, "hasAttr2", '', disables=attr2,
labelWidth=0,
callback=self.set_dimensions)
gui.separator(namesBox)
gui.widgetLabel(namesBox, "Labels")
self.classValuesView = listView = QListView(
selectionMode=QListView.SingleSelection,
sizePolicy=QSizePolicy(QSizePolicy.Ignored,
QSizePolicy.Maximum)
)
listView.setModel(self.class_model)
itemmodels.select_row(listView, 0)
namesBox.layout().addWidget(listView)
self.addClassLabel = QAction(
"+", self,
toolTip="Add new class label",
triggered=self.add_new_class_label
)
self.removeClassLabel = QAction(
unicodedata.lookup("MINUS SIGN"), self,
toolTip="Remove selected class label",
triggered=self.remove_selected_class_label
)
actionsWidget = itemmodels.ModelActionsWidget(
[self.addClassLabel, self.removeClassLabel], self
)
actionsWidget.layout().addStretch(10)
actionsWidget.layout().setSpacing(1)
namesBox.layout().addWidget(actionsWidget)
tBox = gui.vBox(self.controlArea, "Tools", addSpace=True)
buttonBox = gui.hBox(tBox)
toolsBox = gui.widgetBox(buttonBox, orientation=QGridLayout())
self.toolActions = QActionGroup(self)
self.toolActions.setExclusive(True)
self.toolButtons = []
for i, (name, tooltip, tool, icon) in enumerate(self.TOOLS):
action = QAction(
name, self,
toolTip=tooltip,
checkable=tool.checkable,
icon=QIcon(icon),
)
action.triggered.connect(partial(self.set_current_tool, tool))
button = QToolButton(
iconSize=QSize(24, 24),
toolButtonStyle=Qt.ToolButtonTextUnderIcon,
sizePolicy=QSizePolicy(QSizePolicy.MinimumExpanding,
QSizePolicy.Fixed)
)
button.setDefaultAction(action)
self.toolButtons.append((button, tool))
toolsBox.layout().addWidget(button, i / 3, i % 3)
self.toolActions.addAction(action)
for column in range(3):
toolsBox.layout().setColumnMinimumWidth(column, 10)
toolsBox.layout().setColumnStretch(column, 1)
undo = self.undo_stack.createUndoAction(self)
redo = self.undo_stack.createRedoAction(self)
undo.setShortcut(QKeySequence.Undo)
redo.setShortcut(QKeySequence.Redo)
self.addActions([undo, redo])
self.undo_stack.indexChanged.connect(lambda _: self.invalidate())
gui.separator(tBox)
indBox = gui.indentedBox(tBox, sep=8)
form = QFormLayout(
formAlignment=Qt.AlignLeft,
labelAlignment=Qt.AlignLeft,
fieldGrowthPolicy=QFormLayout.AllNonFixedFieldsGrow
)
indBox.layout().addLayout(form)
slider = gui.hSlider(
indBox, self, "brushRadius", minValue=1, maxValue=100,
createLabel=False
#.........这里部分代码省略.........