我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用PyQt5.QtWidgets.QActionGroup()。
def set_menuBar(self): self.actionUeber.triggered.connect(self.aboutDialog.show) self.action_ber_QT.triggered.connect(self.aboutQtDialog.show) self.actionEinstellungen.triggered.connect(self.settingsDialog.show) self.actionLog.triggered.connect(self.logDialog.show) self.actionBeenden.triggered.connect(self.close) self.actionHeute.triggered.connect(self.set_timeEditNow) self.actionAuf_Update_berpr_fen.triggered.connect(self.checkForUpdates) self.actionImportieren.triggered.connect(self.download_match) self.actionHinzuf_gen_reservieren.triggered.connect(self.reserve_match) self.actionL_schen.triggered.connect(self.deleteReservation) self.actionGalerie_hochladen.triggered.connect(self.showGaleryDialog) self.actionBearbeiten.triggered.connect(self.showEditDialog) self.actionSpielbericht_anzeigen.triggered.connect(self.openGameReport) dateRangeGroup = QtWidgets.QActionGroup(self) dateRangeGroup.addAction(self.actionZeitpunkt) dateRangeGroup.addAction(self.actionZeitraum) dateRangeGroup.triggered.connect(self.datePeriodMenu_changed) viewGroup = QtWidgets.QActionGroup(self) viewGroup.addAction(self.actionAnsichtSpiele) viewGroup.addAction(self.actionAnsichtReservierungen) viewGroup.triggered.connect(self.viewMenu_changed)
def init_UI(self): self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle('Dragonfly Frame Viewer') window = QtWidgets.QWidget() self.hbox = QtWidgets.QHBoxLayout() self.frame_panel = frame_panel.Frame_panel(self, powder=self.do_powder, compare=self.do_compare) self.hbox.addWidget(self.frame_panel) # Menu items menubar = self.menuBar() menubar.setNativeMenuBar(False) # Theme picker thememenu = menubar.addMenu('&Theme') self.theme = QtWidgets.QActionGroup(self, exclusive=True) for i, s in enumerate(map(str, list(QtWidgets.QStyleFactory.keys()))): a = self.theme.addAction(QtWidgets.QAction(s, self, checkable=True)) if i == 0: a.setChecked(True) a.triggered.connect(self.theme_changed) thememenu.addAction(a) # Color map picker cmapmenu = menubar.addMenu('&Color Map') self.color_map = QtWidgets.QActionGroup(self, exclusive=True) for i, s in enumerate(['cubehelix', 'CMRmap', 'gray', 'gray_r', 'jet']): a = self.color_map.addAction(QtWidgets.QAction(s, self, checkable=True)) if i == 0: a.setChecked(True) a.triggered.connect(self.cmap_changed) cmapmenu.addAction(a) window.setLayout(self.hbox) self.setCentralWidget(window) self.show()
def subreddit_content_list_right_click(self): self.menu = QtWidgets.QMenu() try: position = self.subreddit_content_list.currentRow() open_file = self.menu.addAction('Open File') self.menu.addSeparator() self.icons_full_width = self.menu.addAction('Icons Full List Width') self.icons_full_width.setCheckable(True) self.icon_size_menu = self.menu.addMenu('Icon Size') self.icon_size_group = QtWidgets.QActionGroup(self) self.icon_size_group.setExclusive(True) self.icon_size_extra_small = self.icon_size_menu.addAction('Extra Small') self.icon_size_extra_small.setCheckable(True) self.icon_size_group.addAction(self.icon_size_extra_small) self.icon_size_small = self.icon_size_menu.addAction('Small') self.icon_size_small.setCheckable(True) self.icon_size_group.addAction(self.icon_size_small) self.icon_size_medium = self.icon_size_menu.addAction('Medium') self.icon_size_medium.setCheckable(True) self.icon_size_group.addAction(self.icon_size_medium) self.icon_size_large = self.icon_size_menu.addAction('Large') self.icon_size_large.setCheckable(True) self.icon_size_group.addAction(self.icon_size_large) self.icon_size_extra_large = self.icon_size_menu.addAction('Extra Large') self.icon_size_extra_large.setCheckable(True) self.icon_size_group.addAction(self.icon_size_extra_large) self.set_context_menu_items_checked() open_file.triggered.connect(lambda: self.open_file(position)) self.icons_full_width.triggered.connect(self.set_icons_full_width) self.icon_size_extra_small.triggered.connect(lambda: self.set_icon_size(48)) self.icon_size_small.triggered.connect(lambda: self.set_icon_size(72)) self.icon_size_medium.triggered.connect(lambda: self.set_icon_size(110)) self.icon_size_large.triggered.connect(lambda: self.set_icon_size(176)) self.icon_size_extra_large.triggered.connect(lambda: self.set_icon_size(256)) except AttributeError: print('SubredditSettingsDialog line 310') self.menu.exec(QtGui.QCursor.pos())
def user_content_list_right_click(self): self.menu = QtWidgets.QMenu() try: position = self.user_content_list.currentRow() open_file = self.menu.addAction('Open File') self.menu.addSeparator() self.icons_full_width = self.menu.addAction('Icons Full List Width') self.icons_full_width.setCheckable(True) self.icon_size_menu = self.menu.addMenu('Icon Size') self.icon_size_group = QtWidgets.QActionGroup(self) self.icon_size_group.setExclusive(True) self.icon_size_extra_small = self.icon_size_menu.addAction('Extra Small') self.icon_size_extra_small.setCheckable(True) self.icon_size_group.addAction(self.icon_size_extra_small) self.icon_size_small = self.icon_size_menu.addAction('Small') self.icon_size_small.setCheckable(True) self.icon_size_group.addAction(self.icon_size_small) self.icon_size_medium = self.icon_size_menu.addAction('Medium') self.icon_size_medium.setCheckable(True) self.icon_size_group.addAction(self.icon_size_medium) self.icon_size_large = self.icon_size_menu.addAction('Large') self.icon_size_large.setCheckable(True) self.icon_size_group.addAction(self.icon_size_large) self.icon_size_extra_large = self.icon_size_menu.addAction('Extra Large') self.icon_size_extra_large.setCheckable(True) self.icon_size_group.addAction(self.icon_size_extra_large) self.set_context_menu_items_checked() open_file.triggered.connect(lambda: self.open_file(position)) self.icons_full_width.triggered.connect(self.set_icons_full_width) self.icon_size_extra_small.triggered.connect(lambda: self.set_icon_size(48)) self.icon_size_small.triggered.connect(lambda: self.set_icon_size(72)) self.icon_size_medium.triggered.connect(lambda: self.set_icon_size(110)) self.icon_size_large.triggered.connect(lambda: self.set_icon_size(176)) self.icon_size_extra_large.triggered.connect(lambda: self.set_icon_size(256)) except AttributeError: print('UserSettingsDialog AttributeError: user_content_right_click') self.menu.exec(QtGui.QCursor.pos())
def setupMenuBar( self, mb ): # --- setup common menus m = mb.addMenu( T_('&File') ) self._addMenu( m, T_('&Preferences…'), self.appActionPreferences, role=QtWidgets.QAction.PreferencesRole ) self._addMenu( m, T_('View Log'), self.appActionViewLog ) self._addMenu( m, T_('E&xit'), self.close, role=QtWidgets.QAction.QuitRole ) m = mb.addMenu( T_('&View') ) tv = self.table_view self._addMenu( m, T_('Show Controlled and Changed files'), tv.setShowControlledAndChangedFiles, checker=tv.checkerShowControlledAndChangedFiles ) self._addMenu( m, T_('Show Controlled and Not Changed files'), tv.setShowControlledAndNotChangedFiles, checker=tv.checkerShowControlledAndNotChangedFiles ) self._addMenu( m, T_('Show Uncontrolled files'), tv.setShowUncontrolledFiles, checker=tv.checkerShowUncontrolledFiles ) self._addMenu( m, T_('Show Ignored files'), tv.setShowIgnoredFiles, checker=tv.checkerShowIgnoredFiles ) m.addSeparator() self.diff_group = QtWidgets.QActionGroup( self ) self.diff_group.setExclusive( True ) self._addMenu( m, T_('Unified diff'), self.setDiffUnified, checker=self.checkerDiffUnified, group=self.diff_group ) self._addMenu( m, T_('Side by side diff'), self.setDiffSideBySide, checker=self.checkerDiffSideBySide, group=self.diff_group ) m.addSeparator() self._addMenu( m, T_('Clear Log Messages'), self.appActionClearLogMessages ) m = mb.addMenu( T_('F&older Actions') ) self._addMenu( m, T_('&Command Shell'), self.treeActionShell, self.enablerFolderExists, 'toolbar_images/terminal.png' ) self._addMenu( m, T_('&File Browser'), self.treeActionFileBrowse, self.enablerFolderExists, 'toolbar_images/file_browser.png' ) m = mb.addMenu( T_('File &Actions') ) self._addMenu( m, T_('Edit'), self.table_view.tableActionEdit, self.table_view.enablerTableFilesExists, 'toolbar_images/edit.png' ) self._addMenu( m, T_('Open'), self.table_view.tableActionOpen, self.table_view.enablerTableFilesExists, 'toolbar_images/open.png' ) # --- setup scm_type specific menus for scm_type in self.all_ui_components: self.debugLog( 'calling setupMenuBar for %r' % (scm_type,) ) self.all_ui_components[ scm_type ].setupMenuBar( mb, self._addMenu ) # --- setup menus less used common menus m = mb.addMenu( T_('&Project') ) self._addMenu( m, T_('Add…'), self.projectActionAdd_Bg ) self._addMenu( m, T_('Settings…'), self.projectActionSettings, self.enablerIsProject ) self._addMenu( m, T_('Delete'), self.projectActionDelete, self.enablerIsProject ) m = mb.addMenu( T_('&Help' ) ) self._addMenu( m, T_("&User Guide…"), self.appActionUserGuide ) self._addMenu( m, T_("&About…"), self.appActionAbout, role=QtWidgets.QAction.AboutRole )
def init_UI(self): self.setAttribute(QtCore.Qt.WA_DeleteOnClose) self.setWindowTitle('Dragonfly Classifier') self.setGeometry(0,0,1100,900) window = QtWidgets.QWidget() hbox = QtWidgets.QHBoxLayout() hbox.setSpacing(0) self.frame_panel = frame_panel.Frame_panel(self) hbox.addWidget(self.frame_panel) window.setLayout(hbox) self.setCentralWidget(window) self.show() self.manual_panel = manual.Manual_panel(self) self.conversion_panel = conversion.Conversion_panel(self) self.embedding_panel = embedding.Embedding_panel(self) self.mlp_panel = mlp.MLP_panel(self) # Menu items menubar = self.menuBar() menubar.setNativeMenuBar(False) # Theme picker thememenu = menubar.addMenu('&Theme') self.theme = QtWidgets.QActionGroup(self, exclusive=True) for i, s in enumerate(map(str, list(QtWidgets.QStyleFactory.keys()))): a = self.theme.addAction(QtWidgets.QAction(s, self, checkable=True)) if i == 0: a.setChecked(True) a.triggered.connect(self.theme_changed) thememenu.addAction(a) # Color map picker cmapmenu = menubar.addMenu('&Color Map') self.color_map = QtWidgets.QActionGroup(self, exclusive=True) for i, s in enumerate(['cubehelix', 'CMRmap', 'gray', 'gray_r', 'jet']): a = self.color_map.addAction(QtWidgets.QAction(s, self, checkable=True)) if i == 0: a.setChecked(True) a.triggered.connect(self.cmap_changed) cmapmenu.addAction(a) toolbox = QtWidgets.QToolBox(self) hbox.addWidget(toolbox) toolbox.setFixedWidth(300) toolbox.addItem(QtWidgets.QWidget(self), '&Display') toolbox.addItem(self.manual_panel, '&Manual') toolbox.addItem(self.conversion_panel, '&Conversion') toolbox.addItem(self.embedding_panel, '&Embedding') toolbox.addItem(self.mlp_panel, 'M&LP') toolbox.currentChanged.connect(self.tab_changed)
def content_display_list_right_click(self): self.menu = QtWidgets.QMenu() try: position = self.content_display_list.currentRow() open_picture = self.menu.addAction('Open In Default Picture Viewer') open_folder = self.menu.addAction('Open Folder') self.menu.addSeparator() self.icons_full_width = self.menu.addAction('Icons Full List Width') self.icons_full_width.setCheckable(True) self.icon_size_menu = self.menu.addMenu('Icon Size') self.icon_size_group = QtWidgets.QActionGroup(self) self.icon_size_group.setExclusive(True) self.icon_size_extra_small = self.icon_size_menu.addAction('Extra Small') self.icon_size_extra_small.setCheckable(True) self.icon_size_group.addAction(self.icon_size_extra_small) self.icon_size_small = self.icon_size_menu.addAction('Small') self.icon_size_small.setCheckable(True) self.icon_size_group.addAction(self.icon_size_small) self.icon_size_medium = self.icon_size_menu.addAction('Medium') self.icon_size_medium.setCheckable(True) self.icon_size_group.addAction(self.icon_size_medium) self.icon_size_large = self.icon_size_menu.addAction('Large') self.icon_size_large.setCheckable(True) self.icon_size_group.addAction(self.icon_size_large) self.icon_size_extra_large = self.icon_size_menu.addAction('Extra Large') self.icon_size_extra_large.setCheckable(True) self.icon_size_group.addAction(self.icon_size_extra_large) self.set_context_menu_items_checked() open_picture.triggered.connect(self.open_file) open_folder.triggered.connect(self.open_folder) self.icons_full_width.triggered.connect(self.set_icons_full_width) self.icon_size_extra_small.triggered.connect(lambda: self.set_icon_size(48)) self.icon_size_small.triggered.connect(lambda: self.set_icon_size(72)) self.icon_size_medium.triggered.connect(lambda: self.set_icon_size(110)) self.icon_size_large.triggered.connect(lambda: self.set_icon_size(176)) self.icon_size_extra_large.triggered.connect(lambda: self.set_icon_size(256)) except AttributeError: print('Exception at line 238') self.menu.exec(QtGui.QCursor.pos())