PYQT QPLAINTEXTEDIT:如何用钥匙组合替换右键



如何用键组合在以下片段中替换"右键"(例如CTRL-S)?我搜索了Google和QT手册,但仍然不知道该怎么做。我是QT的新手。任何帮助将不胜感激。

(p.s。到@ekhumoro:我似乎无法回答您对" pyqt:qtableView中的光标"问题的回答。我在这里使用了您的想法。但是我想使用键组合或按钮。)

class MyDelegate(QStyledItemDelegate):
    contextMenuRequested = pyqtSignal(object, QPoint)
    def __init__(self, parent=None):
        super(MyDelegate, self).__init__(parent)
    def createEditor(self, parent, option, index):
        editor = QPlainTextEdit(parent)
        editor.setContextMenuPolicy(Qt.CustomContextMenu)
        editor.customContextMenuRequested.connect(
            self.commitAndCloseEditor)  # !!! right-click
    def commitAndCloseEditor(self):
        pass

您可以使用QShortCut

class MyDelegate(QStyledItemDelegate):
    def __init__(self, parent=None):
        super(MyDelegate, self).__init__(parent)
        self.shortcut = QtGui.QShortcut(
            QtGui.QKeySequence('Ctrl+S'), parent)
        self.shortcut.activated.connect(self.commitAndCloseEditor)
    def createEditor(self, parent, option, index):
        editor = QPlainTextEdit(parent)
        return editor

最新更新