本文整理汇总了Python中qtpy.QtWidgets.QToolButton.setMenu方法的典型用法代码示例。如果您正苦于以下问题:Python QToolButton.setMenu方法的具体用法?Python QToolButton.setMenu怎么用?Python QToolButton.setMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QToolButton
的用法示例。
在下文中一共展示了QToolButton.setMenu方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ExplorerWidget
# 需要导入模块: from qtpy.QtWidgets import QToolButton [as 别名]
# 或者: from qtpy.QtWidgets.QToolButton import setMenu [as 别名]
class ExplorerWidget(QWidget):
"""Explorer widget"""
sig_option_changed = Signal(str, object)
sig_open_file = Signal(str)
sig_new_file = Signal(str)
redirect_stdio = Signal(bool)
open_dir = Signal(str)
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)
@Slot(bool)
def toggle_icontext(self, state):
"""Toggle icon text"""
self.sig_option_changed.emit('show_icontext', state)
for widget in self.action_widgets:
if widget is not self.button_menu:
if state:
widget.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
else:
widget.setToolButtonStyle(Qt.ToolButtonIconOnly)
示例2: __init__
# 需要导入模块: from qtpy.QtWidgets import QToolButton [as 别名]
# 或者: from qtpy.QtWidgets.QToolButton import setMenu [as 别名]
def __init__(self, *args, **kwargs):
super(MOSViewerToolbar, self).__init__(*args, **kwargs)
# self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon)
# Define icon path
icon_path = os.path.join(os.path.dirname(__file__),
'ui', 'icons')
# Define the toolbar actions
self.cycle_previous_action = QAction(
QIcon(os.path.join(icon_path, "Previous-96.png")),
"Previous", self)
self.cycle_next_action = QAction(
QIcon(os.path.join(icon_path, "Next-96.png")),
"Next", self)
# Include the dropdown widget
self.source_select = QComboBox()
# Add the items to the toolbar
self.addAction(self.cycle_previous_action)
self.addAction(self.cycle_next_action)
self.addWidget(self.source_select)
# Include a button to open spectrum in specviz
self.open_specviz = QAction(
QIcon(os.path.join(icon_path, "External-96.png")),
"Open in SpecViz", self)
# Create a tool button to hold the lock axes menu object
tool_button = QToolButton(self)
tool_button.setText("Axes Settings")
tool_button.setIcon(QIcon(os.path.join(icon_path, "Settings-96.png")))
tool_button.setPopupMode(QToolButton.MenuButtonPopup)
# Create a menu for the axes settings drop down
self.settings_menu = QMenu(self)
# Add lock x axis action
self.lock_x_action = QAction("Lock X Axis",
self.settings_menu)
self.lock_x_action.setCheckable(True)
# Add lock y axis action
self.lock_y_action = QAction("Lock Y Axis",
self.settings_menu)
self.lock_y_action.setCheckable(True)
# Add the actions to the menu
self.settings_menu.addAction(self.lock_x_action)
self.settings_menu.addAction(self.lock_y_action)
# Set the menu object on the tool button
tool_button.setMenu(self.settings_menu)
# Create a widget action object to hold the tool button, this way the
# toolbar behaves the way it's expected to
tool_button_action = QWidgetAction(self)
tool_button_action.setDefaultWidget(tool_button)
self.addAction(tool_button_action)
self.addSeparator()
self.addAction(self.open_specviz)