Intercepting keyboard events before a QTabWidget in PyQt6 There are a couple of main ways to intercept keyboard events before they reach a QTabWidget (and its children widgets) in PyQt6: 1. Using an event filter on the QTabWidget or its QTabBar This is a flexible approach that doesn't require subclassing individual widgets within the tabs. Implement an eventFilter method in a QObject or QWidget (e.g., your main window or a custom class designed for filtering). This method will be called when an event occurs on an object that it's filtering events for. Install the filter on the QTabWidget itself, or more specifically, on the QTabBar component of the QTabWidget, as the tab bar is responsible for handling many key events related to tab switching. In the eventFilter method: Check if the event type is QEvent.KeyPress and the object is the QTabWidget or QTabBar you're interested in. If it's a KeyPress event, you can then inspect the key that was pressed using event.key(). If you want to handle the event yourself and prevent the QTabWidget from processing it, return True from the eventFilter. This signifies that the event has been handled. If you want the QTabWidget to handle the event as usual (e.g., for tab switching via Alt+number shortcuts), return False or simply fall through to the default event filter implementation. For a detailed example of using an event filter to intercept key presses on a QTabBar, please refer to the provided code in the original source. The example demonstrates creating a custom QTabWidget that installs an event filter on its tab bar and handles left and right arrow key presses within the eventFilter method. 2. Reimplementing event() or keyPressEvent() Subclass QTabWidget or the widget containing the QTabWidget. Reimplement the event(self, event) method: This is the lowest-level event handler, receiving all events for the widget. Inside event(), you can check the event type, and if it's a KeyPress event (QEvent.KeyPress), perform your custom handling. If you handle the event, return True to prevent further processing. If you don't handle it, call the base class's event() to allow normal event propagation: return super().event(event). For an example of reimplementing the event() method to intercept key presses, see the provided code snippet in the original source. This example shows a custom QTabWidget that intercepts the 'A' key press within its event() method. Choosing the right method Event Filter: Generally preferred for intercepting events on existing widgets without modifying their core behavior. It's more flexible, especially when you want to filter events for multiple widgets or dynamically change event filtering behavior. Reimplement event() or keyPressEvent(): Suitable when you have a custom widget and want to define its specific key handling logic within that widget itself. Note that Tab and Shift+Tab keys are only passed to keyPressEvent() if not used for focus changes by default; to force processing, you'd need to reimplement event(). Remember to return True from your event handler or filter if you want to consume the event and prevent further processing by the QTabWidget or its children