我们从Python开源项目中,提取了以下5个代码示例,用于说明如何使用PySide.QtGui.QMenuBar()。
def createMenuBar(self): self._menu = QtGui.QMenuBar(self) self._menu.setNativeMenuBar(False) fileMenu = self._menu.addMenu("File") fileMenu.addAction("New") fileMenu.addAction("Open", self.openFileBrowser) fileMenu.addAction("Save", self.saveToFile) fileMenu.addAction("Save As") fileMenu.addSeparator() fileMenu.addAction("Import") fileMenu.addAction("Export") nodeMenu = self._menu.addMenu("Node") nodeMenu.addAction("Create...") nodeMenu.addAction("Duplicate") nodeMenu.addAction("Delete") nodeMenu.addAction("Find...") self._menu.addAction("Save",self.saveToFile) self._layout.addWidget(self._menu)
def initUI(self): self.setMinimumSize(50,100) self.menu = QtGui.QMenuBar() self.menu.addMenu("Test") self.layout = QtGui.QBoxLayout(QtGui.QBoxLayout.TopToBottom,None) self.setLayout(self.layout) self.layout.setContentsMargins(0,0,0,0) self.console = QtGui.QTextEdit() self.console.setReadOnly(True) self.layout.addWidget(self.menu) self.layout.addWidget(self.console)
def setupUi(self, MainWindow): """Setting up UI for Main Window """ MainWindow.setObjectName("MainWindow") MainWindow.resize(804, 600) self.centralwidget = QtGui.QWidget(MainWindow) self.centralwidget.setObjectName("centralwidget") self.horizontalLayout = QtGui.QHBoxLayout(self.centralwidget) self.horizontalLayout.setObjectName("horizontalLayout") self.txtInput = QtGui.QPlainTextEdit(self.centralwidget) self.txtInput.setObjectName("MarkDtextEdit") self.horizontalLayout.addWidget(self.txtInput) self.txtOutput = QtGui.QTextEdit(self.centralwidget) self.txtOutput.setObjectName("MarkDownView") self.horizontalLayout.addWidget(self.txtOutput) MainWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(MainWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 804, 21)) self.menubar.setObjectName("menubar") MainWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(MainWindow) self.statusbar.setObjectName("statusbar") MainWindow.setStatusBar(self.statusbar) self.retranslateUi(MainWindow) QtCore.QMetaObject.connectSlotsByName(MainWindow)
def _initUI(self): self._layout = QtGui.QGridLayout(None) self.setLayout(self._layout) self._layout.setContentsMargins(0,0,0,0) self._menu = QtGui.QMenuBar(self) self._menu.setNativeMenuBar(False) _menuFile = self._menu.addMenu("File") _menuFile.addAction("Open...") _menuFile.addAction("Save") _menuFile.addAction("Save As...") _menuFile.addSeparator() _menuFile.addAction("Execute") _menuFile.addAction("Execute File...") _menuConsole = self._menu.addMenu("Console") _menuConsole.addAction("Show Everything") _menuConsole.addSeparator() _menuConsole.addAction("Show Only Error") _menuConsole.addAction("Show Only Warning") _menuConsole.addAction("Show Only Message") _menuConsole.addSeparator() _menuConsole.addAction("Clear") self._outputConsole = OutputConsole() self._inputConsole = InputConsole() self._layout.addWidget(self._menu,0,0) self._layout.addWidget(self._outputConsole,1,0) self._layout.addWidget(self._inputConsole,2,0)
def setupUi(self, QueryEditorWindow): QueryEditorWindow.setObjectName("QueryEditorWindow") QueryEditorWindow.resize(746, 642) self.centralwidget = QtGui.QWidget(QueryEditorWindow) self.centralwidget.setObjectName("centralwidget") self.verticalLayout_2 = QtGui.QVBoxLayout(self.centralwidget) self.verticalLayout_2.setObjectName("verticalLayout_2") self.verticalLayout = QtGui.QVBoxLayout() self.verticalLayout.setObjectName("verticalLayout") self.tableView = QtGui.QTableView(self.centralwidget) self.tableView.setObjectName("tableView") self.verticalLayout.addWidget(self.tableView) self.verticalLayout_2.addLayout(self.verticalLayout) QueryEditorWindow.setCentralWidget(self.centralwidget) self.menubar = QtGui.QMenuBar(QueryEditorWindow) self.menubar.setGeometry(QtCore.QRect(0, 0, 746, 21)) self.menubar.setObjectName("menubar") self.menuActions = QtGui.QMenu(self.menubar) self.menuActions.setObjectName("menuActions") QueryEditorWindow.setMenuBar(self.menubar) self.statusbar = QtGui.QStatusBar(QueryEditorWindow) self.statusbar.setObjectName("statusbar") QueryEditorWindow.setStatusBar(self.statusbar) self.toolBar = QtGui.QToolBar(QueryEditorWindow) self.toolBar.setObjectName("toolBar") QueryEditorWindow.addToolBar(QtCore.Qt.TopToolBarArea, self.toolBar) self.actionCommit = QtGui.QAction(QueryEditorWindow) icon = QtGui.QIcon() icon.addPixmap(QtGui.QPixmap(":/standard_icons/save.png"), QtGui.QIcon.Active, QtGui.QIcon.On) self.actionCommit.setIcon(icon) self.actionCommit.setObjectName("actionCommit") self.actionUndo = QtGui.QAction(QueryEditorWindow) icon1 = QtGui.QIcon() icon1.addPixmap(QtGui.QPixmap(":/standard_icons/undo.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionUndo.setIcon(icon1) self.actionUndo.setObjectName("actionUndo") self.actionCriteria = QtGui.QAction(QueryEditorWindow) icon2 = QtGui.QIcon() icon2.addPixmap(QtGui.QPixmap(":/standard_icons/filter.png"), QtGui.QIcon.Normal, QtGui.QIcon.Off) self.actionCriteria.setIcon(icon2) self.actionCriteria.setObjectName("actionCriteria") self.actionRefresh = QtGui.QAction(QueryEditorWindow) icon3 = QtGui.QIcon() icon3.addPixmap(QtGui.QPixmap(":/standard_icons/refresh.png"), QtGui.QIcon.Active, QtGui.QIcon.On) self.actionRefresh.setIcon(icon3) self.actionRefresh.setObjectName("actionRefresh") self.menuActions.addAction(self.actionCommit) self.menuActions.addAction(self.actionUndo) self.menuActions.addAction(self.actionCriteria) self.menuActions.addAction(self.actionRefresh) self.menubar.addAction(self.menuActions.menuAction()) self.toolBar.addAction(self.actionCommit) self.toolBar.addAction(self.actionUndo) self.toolBar.addAction(self.actionRefresh) self.toolBar.addAction(self.actionCriteria) self.retranslateUi(QueryEditorWindow) QtCore.QMetaObject.connectSlotsByName(QueryEditorWindow)