Search code examples
qtqt4pyqtpyqt4pyside

Let QTabWidget switch to corresponding page when mouse cursor hover on the tab


I want to show the corresponding page when mouse cursor hover on the tab of a QTabWidget. here

For example, when the mouse cursor hover on tab ‘page2’ here , I hope the QTabWidget shows the corresponding page automatically instead of clicking. How to implement this feature?


Solution

  • You may try adding an event filter on the QTabWidget object's QTabBar in order to trap the mouse move event. In the filter handler, use QTabBar::tabAt( QPoint ) to find which tab is below the cursor. Set up a timer when the cursor first enters a given tab, reset time when cursor leaves it. When the timer fires, switch active tabs.