Skip to content Skip to sidebar Skip to footer

Pyqt Widget Keyboard Focus

First off -- thanks for this group! I started delving into PyQt a month or so ago. In that time, I've bumped up against many questions, and virtually always found an answer here.

Solution 1:

By default, a QWidget does not accept the keyboard focus, so you need to enable it explicitly:

classFormWidget(QWidget):def__init__(self, parent):
        ... 
        self.setFocusPolicy(Qt.StrongFocus)

Solution 2:

Rather than subclassing the child widget or attempting to prevent keystrokes from reaching it, you should consider using an eventFilter to capture events on the child widget. You will see all events before the child widget, and you can suppress or transform them.

http://doc.qt.io/qt-5.5/qobject.html#eventFilter

Post a Comment for "Pyqt Widget Keyboard Focus"