I want to detect middle mouse clicks on a QTabWidget. I was expecting there to be a mouse event related signal on QWidget, but all I am seeing are methods.
Do I need to subclass the QTabWidget and then override said methods in order to do what I want, or am I missing something?
You can either install an event filter on the
QTabBar(returned byQTabWidget.tabBar()) to receive and handle press and release events, or subclassQTabBarto redefinemousePressEventandmouseReleaseEventand replace theQTabBarof theQTabWidgetwithQTabWidget.setTabBar().Example using the event filter:
Example using a QTabBar subclass:
(In case you wonder why there is so much code for such a simple task, a click is defined as a press event followed by a release event at roughly the same spot, so the index of the pressed tab has to be the same as the released tab).