Skip to content
This repository was archived by the owner on Aug 20, 2023. It is now read-only.
This repository was archived by the owner on Aug 20, 2023. It is now read-only.

Escape key doesn't close window #15

@NextDesign1

Description

@NextDesign1

When pressing the escape key, one would expect the window to close. Currently however, it causes the contents of the window to close, but the window remains open.

I have tried both defining the eventFilter, which picks up keypresses, but not escape, and overriding keyPressEvent, which has the same behaviour as eventFilter.

class Boilerplate(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        ...
        self.installEventFilter(self)

    def eventFilter(self, widget, event):
        if event.type() == QtCore.QEvent.KeyPress:
            print 'press'
            if event.key() == QtCore.Qt.Key_Escape:
                print 'escape'
        return super(Boilerplate, self).eventFilter(widget, event)
class Boilerplate(QtWidgets.QMainWindow):
    def __init__(self, parent=None):
        ...
        self.keyPressEvent = self.newKeyPressEvent

    def newKeyPressEvent(self, event):
        print 'press'
        if event.key() == QtCore.Qt.Key_Escape:
            print 'escape'
            self.close()

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions