本文整理汇总了Python中qtpy.QtWidgets.QToolButton.setDefaultAction方法的典型用法代码示例。如果您正苦于以下问题:Python QToolButton.setDefaultAction方法的具体用法?Python QToolButton.setDefaultAction怎么用?Python QToolButton.setDefaultAction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QToolButton
的用法示例。
在下文中一共展示了QToolButton.setDefaultAction方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: action2button
# 需要导入模块: from qtpy.QtWidgets import QToolButton [as 别名]
# 或者: from qtpy.QtWidgets.QToolButton import setDefaultAction [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
示例2: __init__
# 需要导入模块: from qtpy.QtWidgets import QToolButton [as 别名]
# 或者: from qtpy.QtWidgets.QToolButton import setDefaultAction [as 别名]
def __init__(self, parent=None, name_filters=['*.py', '*.pyw'],
show_all=False, show_cd_only=None, show_icontext=True):
QWidget.__init__(self, parent)
# Widgets
self.treewidget = ExplorerTreeWidget(self, show_cd_only=show_cd_only)
button_previous = QToolButton(self)
button_next = QToolButton(self)
button_parent = QToolButton(self)
self.button_menu = QToolButton(self)
menu = QMenu(self)
self.action_widgets = [button_previous, button_next, button_parent,
self.button_menu]
# Actions
icontext_action = create_action(self, _("Show icons and text"),
toggled=self.toggle_icontext)
previous_action = create_action(self, text=_("Previous"),
icon=ima.icon('ArrowBack'),
triggered=self.treewidget.go_to_previous_directory)
next_action = create_action(self, text=_("Next"),
icon=ima.icon('ArrowForward'),
triggered=self.treewidget.go_to_next_directory)
parent_action = create_action(self, text=_("Parent"),
icon=ima.icon('ArrowUp'),
triggered=self.treewidget.go_to_parent_directory)
options_action = create_action(self, text='', tip=_('Options'))
# Setup widgets
self.treewidget.setup(name_filters=name_filters, show_all=show_all)
self.treewidget.chdir(getcwd())
self.treewidget.common_actions += [None, icontext_action]
button_previous.setDefaultAction(previous_action)
previous_action.setEnabled(False)
button_next.setDefaultAction(next_action)
next_action.setEnabled(False)
button_parent.setDefaultAction(parent_action)
self.button_menu.setIcon(ima.icon('tooloptions'))
self.button_menu.setPopupMode(QToolButton.InstantPopup)
self.button_menu.setMenu(menu)
add_actions(menu, self.treewidget.common_actions)
options_action.setMenu(menu)
self.toggle_icontext(show_icontext)
icontext_action.setChecked(show_icontext)
for widget in self.action_widgets:
widget.setAutoRaise(True)
widget.setIconSize(QSize(16, 16))
# Layouts
blayout = QHBoxLayout()
blayout.addWidget(button_previous)
blayout.addWidget(button_next)
blayout.addWidget(button_parent)
blayout.addStretch()
blayout.addWidget(self.button_menu)
layout = QVBoxLayout()
layout.addLayout(blayout)
layout.addWidget(self.treewidget)
self.setLayout(layout)
# Signals and slots
self.treewidget.set_previous_enabled.connect(
previous_action.setEnabled)
self.treewidget.set_next_enabled.connect(next_action.setEnabled)