本文整理汇总了Python中qtpy.QtWidgets.QPushButton.setMenu方法的典型用法代码示例。如果您正苦于以下问题:Python QPushButton.setMenu方法的具体用法?Python QPushButton.setMenu怎么用?Python QPushButton.setMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qtpy.QtWidgets.QPushButton
的用法示例。
在下文中一共展示了QPushButton.setMenu方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _make_export_button
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setMenu [as 别名]
def _make_export_button(self):
"""
Makes the export button menu, containing a list of export
types
:return: The export button menu
"""
export_button = QPushButton("Export")
export_menu = QMenu()
for text, extension in EXPORT_TYPES:
export_menu.addAction(text, lambda ext=extension: self.presenter.export_plots_called(ext))
export_button.setMenu(export_menu)
return export_button
示例2: _make_sort_button
# 需要导入模块: from qtpy.QtWidgets import QPushButton [as 别名]
# 或者: from qtpy.QtWidgets.QPushButton import setMenu [as 别名]
def _make_sort_button(self):
"""
Make the sort button, with separate groups for ascending and
descending, sorting by name or last shown
:return: The sort menu button
"""
sort_button = QPushButton("Sort")
sort_menu = QMenu()
ascending_action = QAction("Ascending", sort_menu, checkable=True)
ascending_action.setChecked(True)
ascending_action.toggled.connect(self.presenter.set_sort_order)
descending_action = QAction("Descending", sort_menu, checkable=True)
order_group = QActionGroup(sort_menu)
order_group.addAction(ascending_action)
order_group.addAction(descending_action)
number_action = QAction("Number", sort_menu, checkable=True)
number_action.setChecked(True)
number_action.toggled.connect(lambda: self.presenter.set_sort_type(Column.Number))
name_action = QAction("Name", sort_menu, checkable=True)
name_action.toggled.connect(lambda: self.presenter.set_sort_type(Column.Name))
last_active_action = QAction("Last Active", sort_menu, checkable=True)
last_active_action.toggled.connect(lambda: self.presenter.set_sort_type(Column.LastActive))
sort_type_group = QActionGroup(sort_menu)
sort_type_group.addAction(number_action)
sort_type_group.addAction(name_action)
sort_type_group.addAction(last_active_action)
sort_menu.addAction(ascending_action)
sort_menu.addAction(descending_action)
sort_menu.addSeparator()
sort_menu.addAction(number_action)
sort_menu.addAction(name_action)
sort_menu.addAction(last_active_action)
sort_button.setMenu(sort_menu)
return sort_button