5

I created a Line with help of QgsMapTool and I'm able to capture the single key in keyPressEvent like this:

class buildingEditTool(QgsMapToolEdit):

    def keyPressEvent(self, event):
        
        if event.key() == Qt.Key_Backspace:
            ''' Do Something'''

then for a key combination I tried

class buildingEditTool(QgsMapToolEdit):

    def keyPressEvent(self, event):
        
        if event.matchs(QKeySequence(ctrl+k)):
            ''' Do Something'''

but it did not work.

How do I capture combination keys in keyPressEvent?

1 Answer 1

6

QKeyEvent has a method modifiers(). You should use it.

def keyPressEvent(self, event):

    if event.modifiers() & Qt.ControlModifier:
        if event.key() == Qt.Key_R:
            print("Ctrl + R")

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.