当前位置: 首页>>代码示例>>Python>>正文


Python QtWidgets.QMenu方法代码示例

本文整理汇总了Python中PySide2.QtWidgets.QMenu方法的典型用法代码示例。如果您正苦于以下问题:Python QtWidgets.QMenu方法的具体用法?Python QtWidgets.QMenu怎么用?Python QtWidgets.QMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide2.QtWidgets的用法示例。


在下文中一共展示了QtWidgets.QMenu方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: onCustomContextMenu

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def onCustomContextMenu(self, localPosition: QPoint):
        """
        Show a custom context menu with a "Download file" action when a file is right-clicked.
        :param localPosition: position where the user clicked.
        """
        selectedFile = self.selectedFile()

        if selectedFile is None:
            return

        globalPosition = self.listWidget.mapToGlobal(localPosition)

        downloadAction = QAction("Download file")
        downloadAction.setEnabled(selectedFile.type in [FileSystemItemType.File])
        downloadAction.triggered.connect(self.downloadFile)

        downloadRecursiveAction = QAction("Download files recursively")
        downloadRecursiveAction.setEnabled(selectedFile.type in [FileSystemItemType.Directory])
        downloadRecursiveAction.triggered.connect(self.downloadDirectoryRecursively)

        itemMenu = QMenu()
        itemMenu.addAction(downloadAction)
        itemMenu.addAction(downloadRecursiveAction)

        itemMenu.exec_(globalPosition) 
开发者ID:GoSecure,项目名称:pyrdp,代码行数:27,代码来源:FileSystemWidget.py

示例2: qui_menu

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def qui_menu(self, action_list_str, menu_str):
        # qui menu creation
        # syntax: self.qui_menu('right_menu_createFolder_atn;Create Folder,Ctrl+D | right_menu_openFolder_atn;Open Folder', 'right_menu')
        if menu_str not in self.uiList.keys():
            self.uiList[menu_str] = QtWidgets.QMenu()
        create_opt_list = [ x.strip() for x in action_list_str.split('|') ]
        for each_creation in create_opt_list:
            ui_info = [ x.strip() for x in each_creation.split(';') ]
            atn_name = ui_info[0]
            atn_title = ''
            atn_hotkey = ''
            if len(ui_info) > 1:
                options = ui_info[1].split(',')
                atn_title = '' if len(options) < 1 else options[0]
                atn_hotkey = '' if len(options) < 2 else options[1]
            if atn_name != '':
                if atn_name == '_':
                    self.uiList[menu_str].addSeparator()
                else:
                    if atn_name not in self.uiList.keys():
                        self.uiList[atn_name] = QtWidgets.QAction(atn_title, self)
                        if atn_hotkey != '':
                            self.uiList[atn_name].setShortcut(QtGui.QKeySequence(atn_hotkey))
                    self.uiList[menu_str].addAction(self.uiList[atn_name]) 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:26,代码来源:universal_tool_template_1116.py

示例3: qui_menubar

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def qui_menubar(self, menu_list_str):
        if not isinstance(self, QtWidgets.QMainWindow):
            print("Warning: Only QMainWindow can have menu bar.")
            return
        menubar = self.menuBar()
        create_opt_list = [ x.strip() for x in menu_list_str.split('|') ]
        for each_creation in create_opt_list:
            ui_info = [ x.strip() for x in each_creation.split(';') ]
            menu_name = ui_info[0]
            menu_title = ''
            if len(ui_info) > 1:
                menu_title = ui_info[1]
            if menu_name not in self.uiList.keys():
                self.uiList[menu_name] = QtWidgets.QMenu(menu_title)
            menubar.addMenu(self.uiList[menu_name])
    
    #=======================================
    # ui creation functions
    #======================================= 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:21,代码来源:universal_tool_template_1116.py

示例4: qui_menubar

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def qui_menubar(self, menu_list_str):
        if not isinstance(self, QtWidgets.QMainWindow):
            print("Warning: Only QMainWindow can have menu bar.")
            return
        menubar = self.menuBar()
        create_opt_list = [ x.strip() for x in menu_list_str.split('|') ]
        for each_creation in create_opt_list:
            ui_info = [ x.strip() for x in each_creation.split(';') ]
            menu_name = ui_info[0]
            menu_title = ''
            if len(ui_info) > 1:
                menu_title = ui_info[1]
            if menu_name not in self.uiList.keys():
                self.uiList[menu_name] = QtWidgets.QMenu(menu_title)
            menubar.addMenu(self.uiList[menu_name])
    # compatible hold function 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:18,代码来源:universal_tool_template_1020.py

示例5: setLang

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def setLang(self, langName):
        uiList_lang_read = self.memoData['lang'][langName]
        for ui_name in uiList_lang_read:
            ui_element = self.uiList[ui_name]
            if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]:
                # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setText(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]:
                # uiType: QMenu, QGroupBox
                if uiList_lang_read[ui_name] != "":
                    ui_element.setTitle(uiList_lang_read[ui_name])
            elif type(ui_element) in [ QtWidgets.QTabWidget]:
                # uiType: QTabWidget
                tabCnt = ui_element.count()
                if uiList_lang_read[ui_name] != "":
                    tabNameList = uiList_lang_read[ui_name].split(';')
                    if len(tabNameList) == tabCnt:
                        for i in range(tabCnt):
                            if tabNameList[i] != "":
                                ui_element.setTabText(i,tabNameList[i])
            elif type(ui_element) == str:
                # uiType: string for msg
                if uiList_lang_read[ui_name] != "":
                    self.uiList[ui_name] = uiList_lang_read[ui_name] 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:27,代码来源:UITranslator.py

示例6: qui_menu

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def qui_menu(self, action_list_str, menu_str):
        # qui menu creation
        # syntax: self.qui_menu('right_menu_createFolder_atn;Create Folder,Ctrl+D | right_menu_openFolder_atn;Open Folder', 'right_menu')
        if menu_str not in self.uiList.keys():
            self.uiList[menu_str] = QtWidgets.QMenu()
        create_opt_list = [ x.strip() for x in action_list_str.split('|') ]
        for each_creation in create_opt_list:
            ui_info = [ x.strip() for x in each_creation.split(';') ]
            atn_name = ui_info[0]
            atn_title = ''
            atn_hotkey = ''
            if len(ui_info) > 1:
                options = ui_info[1].split(',')
                atn_title = '' if len(options) < 1 else options[0]
                atn_hotkey = '' if len(options) < 2 else options[1]
            if atn_name != '':
                if atn_name not in self.uiList.keys():
                    self.uiList[atn_name] = QtWidgets.QAction(atn_title, self)
                    if atn_hotkey != '':
                        self.uiList[atn_name].setShortcut(QtGui.QKeySequence(atn_hotkey))
                self.uiList[menu_str].addAction(self.uiList[atn_name]) 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:23,代码来源:universal_tool_template_1010.py

示例7: contextMenuEvent

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def contextMenuEvent(self, event):
        sr = self.current_state_record()

        menu = QMenu("", self)

        menu.addAction('New state...', self._action_new_state)
        menu.addSeparator()

        a = menu.addAction('Duplicate state', self._action_duplicate)
        if sr is None:
            a.setDisabled(True)

        a = menu.addAction('Delete state', self._action_delete)
        if sr is None:
            a.setDisabled(True)

        a = menu.addAction('New simulation manager', self._action_new_simulation_manager)
        if sr is None:
            a.setDisabled(True)

        menu.exec_(event.globalPos()) 
开发者ID:angr,项目名称:angr-management,代码行数:23,代码来源:qstate_table.py

示例8: qmenu

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def qmenu(self, extra_entries=None):
        if extra_entries is None:
            extra_entries = []
        else:
            extra_entries = [MenuSeparator() if entry is None else MenuEntry(*entry) for entry in extra_entries]

        if not extra_entries and self._qmenu is not None:
            # in order to use the cached result, must not have extra entries
            return self._qmenu

        if self.parent is not None:
            menu = QMenu(self.caption, self.parent)
        else:
            menu = QMenu(self.caption)

        for entry in self.entries + extra_entries:
            self._translate_element(menu, entry)

        # in order to cache the result, must not have extra entries
        if not extra_entries:
            self._qmenu = menu

        return menu 
开发者ID:angr,项目名称:angr-management,代码行数:25,代码来源:menu.py

示例9: contextMenuEvent

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def contextMenuEvent(self, event):
        """creates popup menu for the graphicsview"""

        menu = QtWidgets.QMenu(self)

        fitairfoil = menu.addAction('Fit airfoil in view')
        fitairfoil.setShortcut('CTRL+f')

        fitall = menu.addAction('Fit all items in view')
        fitall.setShortcut('HOME, CTRL+SHIFT+f')

        menu.addSeparator()

        delitems = menu.addAction('Delete airfoil')
        delitems.setShortcut('Del')

        menu.addSeparator()

        togglebg = menu.addAction('Toggle background')
        togglebg.setShortcut('CTRL+b')

        action = menu.exec_(self.mapToGlobal(event.pos()))

        if action == togglebg:
            self.parent.slots.onBackground()
        elif action == fitairfoil:
            self.parent.slots.fitAirfoilInView()
        elif action == fitall:
            self.parent.slots.onViewAll()
        # remove all selected items from the scene
        elif action == delitems:
            self.parent.slots.removeAirfoil()

        # call corresponding base class method
        super().contextMenuEvent(event) 
开发者ID:chiefenne,项目名称:PyAero,代码行数:37,代码来源:GraphicsView.py

示例10: setLang

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def setLang(self, langName):
        lang_data = self.memoData['lang'][langName]
        for ui_name in lang_data.keys():
            if ui_name in self.uiList.keys() and lang_data[ui_name] != '':
                ui_element = self.uiList[ui_name]
                # '' means no translation availdanle in that data file
                if isinstance(ui_element, (QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox) ):
                    # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox
                    ui_element.setText(lang_data[ui_name])
                elif isinstance(ui_element, (QtWidgets.QGroupBox, QtWidgets.QMenu) ):
                    # uiType: QMenu, QGroupBox
                    ui_element.setTitle(lang_data[ui_name])
                elif isinstance(ui_element, QtWidgets.QTabWidget):
                    # uiType: QTabWidget
                    tabCnt = ui_element.count()
                    tabNameList = lang_data[ui_name].split(';')
                    if len(tabNameList) == tabCnt:
                        for i in range(tabCnt):
                            if tabNameList[i] != '':
                                ui_element.setTabText(i,tabNameList[i])
                elif isinstance(ui_element, QtWidgets.QComboBox):
                    # uiType: QComboBox
                    itemCnt = ui_element.count()
                    itemNameList = lang_data[ui_name].split(';')
                    ui_element.clear()
                    ui_element.addItems(itemNameList)
                elif isinstance(ui_element, QtWidgets.QTreeWidget):
                    # uiType: QTreeWidget
                    labelCnt = ui_element.headerItem().columnCount()
                    labelList = lang_data[ui_name].split(';')
                    ui_element.setHeaderLabels(labelList)
                elif isinstance(ui_element, QtWidgets.QTableWidget):
                    # uiType: QTableWidget
                    colCnt = ui_element.columnCount()
                    headerList = lang_data[ui_name].split(';')
                    cur_table.setHorizontalHeaderLabels( headerList )
                elif isinstance(ui_element, (str, unicode) ):
                    # uiType: string for msg
                    self.uiList[ui_name] = lang_data[ui_name] 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:41,代码来源:universal_tool_template_1116.py

示例11: qui_atn

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def qui_atn(self, ui_name, title, tip=None, icon=None, parent=None, key=None):
        self.uiList[ui_name] = QtWidgets.QAction(title, self)
        if icon!=None:
            self.uiList[ui_name].setIcon(QtGui.QIcon(icon))
        if tip !=None:
            self.uiList[ui_name].setStatusTip(tip)
        if key != None:
            self.uiList[ui_name].setShortcut(QtGui.QKeySequence(key))
        if parent !=None:
            if isinstance(parent, (str, unicode)) and parent in self.uiList.keys():
                self.uiList[parent].addAction(self.uiList[ui_name])
            elif isinstance(parent, QtWidgets.QMenu):
                parent.addAction(self.uiList[ui_name])
        return ui_name 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:16,代码来源:universal_tool_template_1116.py

示例12: qui_menubar

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def qui_menubar(self, menu_list_str):
        if not isinstance(self, QtWidgets.QMainWindow):
            print("Warning: Only QMainWindow can have menu bar.")
            return
        menubar = self.menuBar()
        create_opt_list = [ x.strip() for x in menu_list_str.split('|') ]
        for each_creation in create_opt_list:
            ui_info = [ x.strip() for x in each_creation.split(';') ]
            menu_name = ui_info[0]
            menu_title = ''
            if len(ui_info) > 1:
                menu_title = ui_info[1]
            if menu_name not in self.uiList.keys():
                self.uiList[menu_name] = QtWidgets.QMenu(menu_title)
            menubar.addMenu(self.uiList[menu_name]) 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:17,代码来源:universal_tool_template_2010.py

示例13: contextMenuEvent

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def contextMenuEvent(self, event):
        menu = QtWidgets.QMenu(self)
        quitAction = menu.addAction("Quit")
        action = menu.exec_(self.mapToGlobal(event.pos()))
        if action == quitAction:
            self.close() 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:8,代码来源:UITranslator.py

示例14: loadLang

# 需要导入模块: from PySide2 import QtWidgets [as 别名]
# 或者: from PySide2.QtWidgets import QMenu [as 别名]
def loadLang(self):
        self.quickMenu(['language_menu;&Language'])
        cur_menu = self.uiList['language_menu']
        self.quickMenuAction('langDefault_atnLang', 'Default','','langDefault.png', cur_menu)
        cur_menu.addSeparator()
        self.uiList['langDefault_atnLang'].triggered.connect(partial(self.setLang,'default'))
        # store default language
        self.memoData['lang']={}
        self.memoData['lang']['default']={}
        for ui_name in self.uiList:
            ui_element = self.uiList[ui_name]
            if type(ui_element) in [ QtWidgets.QLabel, QtWidgets.QPushButton, QtWidgets.QAction, QtWidgets.QCheckBox ]:
                # uiType: QLabel, QPushButton, QAction(menuItem), QCheckBox
                self.memoData['lang']['default'][ui_name] = str(ui_element.text())
            elif type(ui_element) in [ QtWidgets.QGroupBox, QtWidgets.QMenu ]:
                # uiType: QMenu, QGroupBox
                self.memoData['lang']['default'][ui_name] = str(ui_element.title())
            elif type(ui_element) in [ QtWidgets.QTabWidget]:
                # uiType: QTabWidget
                tabCnt = ui_element.count()
                tabNameList = []
                for i in range(tabCnt):
                    tabNameList.append(str(ui_element.tabText(i)))
                self.memoData['lang']['default'][ui_name]=';'.join(tabNameList)
            elif type(ui_element) == str:
                # uiType: string for msg
                self.memoData['lang']['default'][ui_name] = self.uiList[ui_name]
        
        # try load other language
        lang_path = os.path.dirname(self.location) # better in packed than(os.path.abspath(__file__))
        baseName = os.path.splitext( os.path.basename(self.location) )[0]
        for fileName in os.listdir(lang_path):
            if fileName.startswith(baseName+"_lang_"):
                langName = fileName.replace(baseName+"_lang_","").split('.')[0].replace(" ","")
                self.memoData['lang'][ langName ] = self.readRawFile( os.path.join(lang_path,fileName) )
                self.quickMenuAction(langName+'_atnLang', langName.upper(),'',langName + '.png', cur_menu)
                self.uiList[langName+'_atnLang'].triggered.connect(partial(self.setLang,langName))
        # if no language file detected, add export default language option
        if len(self.memoData['lang']) == 1:
            self.quickMenuAction('langExport_atnLang', 'Export Default Language','','langExport.png', cur_menu)
            self.uiList['langExport_atnLang'].triggered.connect(self.exportLang) 
开发者ID:shiningdesign,项目名称:universal_tool_template.py,代码行数:43,代码来源:UITranslator.py


注:本文中的PySide2.QtWidgets.QMenu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。