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


Python QtWidgets.QMenu方法代码示例

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


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

示例1: __init__

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def __init__(self, path, parent=None, slot=None):
        """ Create the action.
        
        :Parameters:
            path : `str`
                Absolute path to open.
            parent : `QtGui.QMenu`
                Menu to add action to.
            slot
                Method to connect openFile signal to
        """
        super(RecentFile, self).__init__(parent)
        self.path = path
        
        # Don't show any query strings or SDF_FORMAT_ARGS in the menu.
        displayName = path.split("?", 1)[0].split(":SDF_FORMAT_ARGS:", 1)[0]
        # Escape any ampersands so that we don't get underlines for Alt+<key> shortcuts.
        displayName = QtCore.QFileInfo(displayName).fileName().replace("&", "&&")
        self.setText(displayName)
        self.setStatusTip(self.path)
        self.triggered.connect(self.onClick)
        if slot is not None:
            self.openFile.connect(slot) 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:25,代码来源:__init__.py

示例2: addHistoryAction

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def addHistoryAction(self, menu, index=0):
        """ Create a menu action for the current path.
        
        :Parameters:
            menu : `QtWidgets.QMenu`
                Menu to add action to
            index : `int`
                Index to insert action at.
                Defaults to the start of the menu if the index isn't given or is invalid.
        """
        item = self.history[self.historyIndex]
        action = RecentFile(item.url.toString(), menu, self.onHistoryActionTriggered)
        action.historyIndex = self.historyIndex
        
        try:
            before = menu.actions()[index]
        except IndexError:
            before = None
        menu.insertAction(before, action) 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:21,代码来源:__init__.py

示例3: mousePressEvent

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def mousePressEvent(self, evnt):
        super(TesterList, self).mousePressEvent(evnt)

        if QtCore.Qt.MouseButton.LeftButton == evnt.button():
            index = self.indexAt(evnt.pos())
            if index.row() < 0:
                self.__current_tester = None
                self.clearSelection()

        elif QtCore.Qt.MouseButton.RightButton == evnt.button():
            menu = QtWidgets.QMenu(self)
            test = QtWidgets.QAction("Single Test", menu)
            menu.addAction(test)
            pos = self.mapToGlobal(evnt.pos())
            menu.popup(QtCore.QPoint(pos.x() - 10, pos.y() - 10))
            test.triggered.connect(self.__testTriggered) 
开发者ID:sol-ansano-kim,项目名称:medic,代码行数:18,代码来源:widgets.py

示例4: customTabWidgetContextMenu

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def customTabWidgetContextMenu(self, pos):
        """ Slot for the right-click context menu for the tab widget.
        
        :Parameters:
            pos : `QtCore.QPoint`
                Position of the right-click
        """
        menu = QtWidgets.QMenu(self)
        menu.addAction(self.actionNewTab)
        menu.addSeparator()
        menu.addAction(self.actionRefreshTab)
        menu.addAction(self.actionDuplicateTab)
        menu.addSeparator()
        menu.addAction(self.actionCloseTab)
        menu.addAction(self.actionCloseOther)
        menu.addAction(self.actionCloseRight)
        
        self.contextMenuPos = self.tabWidget.tabBar.mapFromParent(pos)
        indexOfClickedTab = self.tabWidget.tabBar.tabAt(self.contextMenuPos)
        if indexOfClickedTab == -1:
            self.actionCloseTab.setEnabled(False)
            self.actionCloseOther.setEnabled(False)
            self.actionCloseRight.setEnabled(False)
            self.actionRefreshTab.setEnabled(False)
            self.actionDuplicateTab.setEnabled(False)
        else:
            self.actionCloseTab.setEnabled(True)
            self.actionCloseOther.setEnabled(self.tabWidget.count() > 1)
            self.actionCloseRight.setEnabled(indexOfClickedTab < self.tabWidget.count() - 1)
            self.actionRefreshTab.setEnabled(bool(self.tabWidget.widget(indexOfClickedTab).getCurrentPath()))
            self.actionDuplicateTab.setEnabled(True)
        
        menu.exec_(self.tabWidget.mapToGlobal(pos))
        del menu
        self.contextMenuPos = None 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:37,代码来源:__init__.py

示例5: generate

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def generate(self):
        menuData = self.builder.get()
        menu = QMenu()
        for menuEntry in menuData:
            self.__createMenuEntry(menu, menuEntry)
        return menu 
开发者ID:wonderworks-software,项目名称:PyFlow,代码行数:8,代码来源:ContextMenuGenerator.py

示例6: __init__

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def __init__(self, parent=None, dataSetCallback=None, defaultValue=None, **kwds):
        super(InputWidgetRaw, self).__init__(parent=parent)
        self._defaultValue = defaultValue
        # function with signature void(object)
        # this will set data to pin
        self.dataSetCallback = dataSetCallback
        self._widget = None
        self._menu = QMenu()
        self.actionReset = self._menu.addAction("ResetValue")
        self.actionReset.triggered.connect(self.onResetValue) 
开发者ID:wonderworks-software,项目名称:PyFlow,代码行数:12,代码来源:InputWidgets.py

示例7: addItemToMenu

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def addItemToMenu(self, path, menu, slot, maxLen=None, start=0, end=None):
        """ Add a path to a history menu.
        
        :Parameters:
            path : `str`
                The full path to add to the history menu.
            menu : `QtGui.QMenu`
                Menu to add history item to.
            slot
                Method to connect action to
            maxLen : `int`
                Optional maximum number of history items in the menu.
            start : `int`
                Optional number of actions at the start of the menu to ignore.
            end : `int`
                Optional number of actions at the end of the menu to ignore.
        """
        # Get the current actions.
        actions = menu.actions()
        numAllActions = len(actions)
        
        if end is not None:
            end = -end
            numActions = numAllActions - start + end
        else:
            numActions = numAllActions - start
        
        # Validate the start, end, and maxLen numbers.
        if start < 0 or maxLen <= 0 or numActions < 0:
            logger.error("Invalid start/end values provided for inserting action in menu.\n"
                         "start: {}, end: {}, menu length: {}".format(start, end, numAllActions))
        elif numActions == 0:
            # There are not any actions yet, so just add or insert it.
            action = RecentFile(path, menu, slot)
            if start != 0 and numAllActions > start:
                menu.insertAction(actions[start], action)
            else:
                menu.addAction(action)
        else:
            alreadyInMenu = False
            for action in actions[start:end]:
                if path == action.path:
                    alreadyInMenu = True
                    # Move to the top if there is more than one action and it isn't already at the top.
                    if numActions > 1 and action != actions[start]:
                        menu.removeAction(action)
                        menu.insertAction(actions[start], action)
                    break
            if not alreadyInMenu:
                action = RecentFile(path, menu, slot)
                menu.insertAction(actions[start], action)
                if maxLen is not None and numActions == maxLen:
                    menu.removeAction(actions[start + maxLen - 1]) 
开发者ID:dreamworksanimation,项目名称:usdmanager,代码行数:55,代码来源:__init__.py

示例8: __init__

# 需要导入模块: from Qt import QtWidgets [as 别名]
# 或者: from Qt.QtWidgets import QMenu [as 别名]
def __init__(self, parent=None, searchByHeaders=False):
        super(PropertiesWidget, self).__init__(parent)
        self.setWindowTitle("Properties view")
        self.mainLayout = QtWidgets.QVBoxLayout(self)
        self.mainLayout.setObjectName("propertiesMainLayout")
        self.mainLayout.setContentsMargins(2, 2, 2, 2)
        self.searchBox = QtWidgets.QLineEdit(self)
        self.searchBox.setObjectName("lineEdit")
        self.searchBox.setPlaceholderText(str("search..."))
        self.searchBox.textChanged.connect(self.filterByHeaders if searchByHeaders else self.filterByHeadersAndFields)
        self.searchBoxWidget = QtWidgets.QWidget()
        self.searchBoxLayout = QtWidgets.QHBoxLayout(self.searchBoxWidget)
        self.searchBoxLayout.setContentsMargins(1, 1, 1, 1)
        self.searchBoxLayout.addWidget(self.searchBox)

        # self.settingsButton = QtWidgets.QToolButton()
        # self.settingsButton.setIcon(QtGui.QIcon(":/settings.png"))
        # self.settingsMenu = QtWidgets.QMenu()
        # self.editPropertiesAction = QtWidgets.QAction("Edit Parameter Interface", None)
        # self.settingsMenu.addAction(self.editPropertiesAction)
        # self.settingsButton.setMenu(self.settingsMenu)
        # self.editPropertiesAction.triggered.connect(self.showPropertyEditor)
        #self.settingsButton.clicked.connect(self.spawnDuplicate.emit)
        # self.settingsButton.setPopupMode(QtWidgets.QToolButton.InstantPopup)

        self.lockCheckBox = QtWidgets.QToolButton()
        self.lockCheckBox.setCheckable(True)
        self.lockCheckBox.setIcon(QtGui.QIcon(':/unlocked.png'))
        self.lockCheckBox.toggled.connect(self.changeLockIcon)
        self.searchBoxLayout.addWidget(self.lockCheckBox)
        self.tearOffCopy = QtWidgets.QToolButton()
        self.tearOffCopy.setIcon(QtGui.QIcon(":/tear_off_copy_bw.png"))
        self.tearOffCopy.clicked.connect(self.spawnDuplicate.emit)
        self.searchBoxLayout.addWidget(self.tearOffCopy)
        self.mainLayout.addWidget(self.searchBoxWidget)
        self.searchBoxWidget.hide()
        self.contentLayout = QtWidgets.QVBoxLayout()
        self.contentLayout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
        self.mainLayout.addLayout(self.contentLayout)
        self.spacerItem = QtWidgets.QSpacerItem(20, 40, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Expanding)
        self.mainLayout.addItem(self.spacerItem)
        self.mainLayout.setSizeConstraint(QtWidgets.QLayout.SetMinAndMaxSize)
        self.setSizePolicy(QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding)) 
开发者ID:wonderworks-software,项目名称:PyFlow,代码行数:45,代码来源:PropertiesFramework.py


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