本文整理汇总了Python中PyQt5.QtWidgets.QMenuBar.setContextMenuPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QMenuBar.setContextMenuPolicy方法的具体用法?Python QMenuBar.setContextMenuPolicy怎么用?Python QMenuBar.setContextMenuPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QMenuBar
的用法示例。
在下文中一共展示了QMenuBar.setContextMenuPolicy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QMenuBar [as 别名]
# 或者: from PyQt5.QtWidgets.QMenuBar import setContextMenuPolicy [as 别名]
class MainWindow(QMainWindow, metaclass=QSingleton):
new_session = pyqtSignal()
save_session = pyqtSignal(str)
open_session = pyqtSignal(str)
def __init__(self):
super().__init__()
self.setMinimumSize(500, 400)
self._cue_add_menu = {}
self.layout = None
# Status Bar
self.statusBar = QStatusBar(self)
self.setStatusBar(self.statusBar)
MainActionsHandler().action_done.connect(self._action_done)
MainActionsHandler().action_undone.connect(self._action_undone)
MainActionsHandler().action_redone.connect(self._action_redone)
# Menubar
self.menubar = QMenuBar(self)
self.menubar.setGeometry(QtCore.QRect(0, 0, 0, 25))
self.menubar.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
self.menuFile = QMenu(self.menubar)
self.menuEdit = QMenu(self.menubar)
self.menuLayout = QMenu(self.menubar)
self.menuTools = QMenu(self.menubar)
self.menuAbout = QMenu(self.menubar)
self.menubar.addMenu(self.menuFile)
self.menubar.addMenu(self.menuEdit)
self.menubar.addMenu(self.menuLayout)
self.menubar.addMenu(self.menuTools)
self.menubar.addMenu(self.menuAbout)
self.setMenuBar(self.menubar)
# menuFile
self.newSessionAction = QAction(self)
self.newSessionAction.triggered.connect(self._new_session)
self.openSessionAction = QAction(self)
self.openSessionAction.triggered.connect(self._load_from_file)
self.saveSessionAction = QAction(self)
self.saveSessionAction.triggered.connect(self._save)
self.saveSessionWithName = QAction(self)
self.saveSessionWithName.triggered.connect(self._save_with_name)
self.editPreferences = QAction(self)
self.editPreferences.triggered.connect(self._show_preferences)
self.fullScreenAction = QAction(self)
self.fullScreenAction.triggered.connect(self._fullscreen)
self.fullScreenAction.setCheckable(True)
self.exitAction = QAction(self)
self.exitAction.triggered.connect(self._exit)
self.menuFile.addAction(self.newSessionAction)
self.menuFile.addAction(self.openSessionAction)
self.menuFile.addSeparator()
self.menuFile.addAction(self.saveSessionAction)
self.menuFile.addAction(self.saveSessionWithName)
self.menuFile.addSeparator()
self.menuFile.addAction(self.editPreferences)
self.menuFile.addSeparator()
self.menuFile.addAction(self.fullScreenAction)
self.menuFile.addSeparator()
self.menuFile.addAction(self.exitAction)
# menuEdit
self.actionUndo = QAction(self)
self.actionUndo.triggered.connect(MainActionsHandler().undo_action)
self.actionRedo = QAction(self)
self.actionRedo.triggered.connect(MainActionsHandler().redo_action)
self.multiEdit = QAction(self)
self.selectAll = QAction(self)
self.deselectAll = QAction(self)
self.invertSelection = QAction(self)
self.cueSeparator = self.menuEdit.addSeparator()
self.menuEdit.addAction(self.actionUndo)
self.menuEdit.addAction(self.actionRedo)
self.menuEdit.addSeparator()
self.menuEdit.addAction(self.selectAll)
self.menuEdit.addAction(self.deselectAll)
self.menuEdit.addAction(self.invertSelection)
self.menuEdit.addSeparator()
self.menuEdit.addAction(self.multiEdit)
# menuAbout
self.actionAbout = QAction(self)
self.actionAbout.triggered.connect(about.About(self).show)
self.actionAbout_Qt = QAction(self)
self.actionAbout_Qt.triggered.connect(qApp.aboutQt)
self.menuAbout.addAction(self.actionAbout)
self.menuAbout.addSeparator()
self.menuAbout.addAction(self.actionAbout_Qt)
# Set component text
#.........这里部分代码省略.........
示例2: MainWindow
# 需要导入模块: from PyQt5.QtWidgets import QMenuBar [as 别名]
# 或者: from PyQt5.QtWidgets.QMenuBar import setContextMenuPolicy [as 别名]
class MainWindow(QMainWindow, metaclass=QSingleton):
new_session = QtCore.pyqtSignal()
save_session = QtCore.pyqtSignal(str)
open_session = QtCore.pyqtSignal(str)
def __init__(self):
super().__init__()
self.setMinimumSize(400, 300)
self._cue_add_menus = {}
self.layout = None
# Define the layout and the main gui's elements
self.centralwidget = QWidget(self)
self.setCentralWidget(self.centralwidget)
self.gridLayout = QGridLayout(self.centralwidget)
self.gridLayout.setContentsMargins(2, 5, 2, 0)
# Status Bar
self.statusBar = QStatusBar(self)
self.setStatusBar(self.statusBar)
ActionsHandler().action_done.connect(self._action_done)
ActionsHandler().action_undone.connect(self._action_undone)
ActionsHandler().action_redone.connect(self._action_redone)
# Menubar
self.menubar = QMenuBar(self)
self.menubar.setGeometry(QtCore.QRect(0, 0, 0, 25))
self.menubar.setContextMenuPolicy(QtCore.Qt.PreventContextMenu)
self.menuFile = QMenu(self.menubar)
self.menuEdit = QMenu(self.menubar)
self.menuLayout = QMenu(self.menubar)
self.menuTools = QMenu(self.menubar)
self.menuAbout = QMenu(self.menubar)
self.menubar.addMenu(self.menuFile)
self.menubar.addMenu(self.menuEdit)
self.menubar.addMenu(self.menuLayout)
self.menubar.addMenu(self.menuTools)
self.menubar.addMenu(self.menuAbout)
self.setMenuBar(self.menubar)
# menuFile
self.newSessionAction = QAction(self, triggered=self._startup)
self.openSessionAction = QAction(self, triggered=self._load_from_file)
self.saveSessionAction = QAction(self, triggered=self.save)
self.saveSessionWithName = QAction(self, triggered=self.save_with_name)
self.editPreferences = QAction(self, triggered=self.show_preferences)
self.fullScreenAction = QAction(self, triggered=self._fullscreen)
self.fullScreenAction.setCheckable(True)
self.exitAction = QAction(self, triggered=self.exit)
self.menuFile.addAction(self.newSessionAction)
self.menuFile.addAction(self.openSessionAction)
self.menuFile.addSeparator()
self.menuFile.addAction(self.saveSessionAction)
self.menuFile.addAction(self.saveSessionWithName)
self.menuFile.addSeparator()
self.menuFile.addAction(self.editPreferences)
self.menuFile.addSeparator()
self.menuFile.addAction(self.fullScreenAction)
self.menuFile.addSeparator()
self.menuFile.addAction(self.exitAction)
# menuEdit
self.actionUndo = QAction(self)
self.actionUndo.triggered.connect(
lambda: ActionsHandler().undo_action())
self.actionRedo = QAction(self)
self.actionRedo.triggered.connect(
lambda: ActionsHandler().redo_action())
self.multiEdit = QAction(self)
self.selectAll = QAction(self)
self.deselectAll = QAction(self)
self.invertSelection = QAction(self)
self.cueSeparator = self.menuEdit.addSeparator()
self.menuEdit.addAction(self.actionUndo)
self.menuEdit.addAction(self.actionRedo)
self.menuEdit.addSeparator()
self.menuEdit.addAction(self.selectAll)
self.menuEdit.addAction(self.deselectAll)
self.menuEdit.addAction(self.invertSelection)
self.menuEdit.addSeparator()
self.menuEdit.addAction(self.multiEdit)
# menuAbout
self.actionAbout = QAction(self)
self.actionAbout.triggered.connect(about.About(self).show)
self.actionAbout_Qt = QAction(self)
self.actionAbout_Qt.triggered.connect(qApp.aboutQt)
self.menuAbout.addAction(self.actionAbout)
self.menuAbout.addSeparator()
self.menuAbout.addAction(self.actionAbout_Qt)
#.........这里部分代码省略.........