本文整理汇总了Python中qtpy.QtWidgets.QToolButton.setPopupMode方法的典型用法代码示例。如果您正苦于以下问题:Python QToolButton.setPopupMode方法的具体用法?Python QToolButton.setPopupMode怎么用?Python QToolButton.setPopupMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QToolButton
的用法示例。
在下文中一共展示了QToolButton.setPopupMode方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from qtpy.QtWidgets import QToolButton [as 别名]
# 或者: from qtpy.QtWidgets.QToolButton import setPopupMode [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)
示例2: ExplorerWidget
# 需要导入模块: from qtpy.QtWidgets import QToolButton [as 别名]
# 或者: from qtpy.QtWidgets.QToolButton import setPopupMode [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)
示例3: CondaPackagesWidget
# 需要导入模块: from qtpy.QtWidgets import QToolButton [as 别名]
# 或者: from qtpy.QtWidgets.QToolButton import setPopupMode [as 别名]
#.........这里部分代码省略.........
icon_options = ima.icon('tooloptions')
except Exception:
import qtawesome as qta
icon_options = qta.icon('fa.cog')
# Widgets
self.cancel_dialog = ClosePackageManagerDialog
self.bbox = QDialogButtonBox(Qt.Horizontal)
self.button_cancel = QPushButton('Cancel')
self.button_channels = QPushButton(_('Channels'))
self.button_ok = QPushButton(_('Ok'))
self.button_update = QPushButton(_('Update index...'))
self.button_apply = QPushButton(_('Apply'))
self.button_clear = QPushButton(_('Clear'))
self.button_options = QToolButton()
self.combobox_filter = DropdownPackageFilter(self)
self.frame_top = FramePackageTop()
self.frame_bottom = FramePackageTop()
self.progress_bar = ProgressBarPackage(self)
self.status_bar = LabelPackageStatus(self)
self.table = TableCondaPackages(self)
self.textbox_search = LineEditSearch(self)
self.widgets = [self.button_update, self.button_channels,
self.combobox_filter, self.textbox_search, self.table,
self.button_ok, self.button_apply, self.button_clear,
self.button_options]
self.table_first_row = FirstRowWidget(
widget_before=self.textbox_search)
self.table_last_row = LastRowWidget(
widgets_after=[self.button_apply, self.button_clear,
self.button_cancel, self.combobox_filter])
# Widget setup
self.button_options.setPopupMode(QToolButton.InstantPopup)
self.button_options.setIcon(icon_options)
self.button_options.setAutoRaise(True)
max_height = self.status_bar.fontMetrics().height()
max_width = self.textbox_search.fontMetrics().width('M'*23)
self.bbox.addButton(self.button_ok, QDialogButtonBox.ActionRole)
self.button_ok.setAutoDefault(True)
self.button_ok.setDefault(True)
self.button_ok.setMaximumSize(QSize(0, 0))
self.button_ok.setVisible(False)
self.combobox_filter.addItems([k for k in C.COMBOBOX_VALUES_ORDERED])
self.combobox_filter.setMinimumWidth(120)
self.progress_bar.setMaximumHeight(max_height*1.2)
self.progress_bar.setMaximumWidth(max_height*12)
self.progress_bar.setTextVisible(False)
self.progress_bar.setVisible(False)
self.setMinimumSize(QSize(480, 300))
self.setWindowTitle(_("Conda Package Manager"))
self.status_bar.setFixedHeight(max_height*1.5)
self.textbox_search.setMaximumWidth(max_width)
self.textbox_search.setPlaceholderText('Search Packages')
self.table_first_row.setMaximumHeight(0)
self.table_last_row.setMaximumHeight(0)
self.table_last_row.setVisible(False)
self.table_first_row.setVisible(False)
# Layout
top_layout = QHBoxLayout()
top_layout.addWidget(self.combobox_filter)
top_layout.addWidget(self.button_channels)
top_layout.addWidget(self.button_update)
top_layout.addWidget(self.textbox_search)