【Solved】let QTabWidget show the corresponding page when mouse cursor hover on the tab I want to show the corresponding page when mouse cursor hover
-
let QTabWidget show the 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.
!http://oi43.tinypic.com/2d7sqpf.jpg(http://oi43.tinypic.com/2d7sqpf.jpg)!
For example ,when the mouse cursor hover on tab ‘page2’ here , I hope the QTabWidget show the corresponding page automatically instead of clicking,so how to implement this feature ? -
Hi,
Just a quick idea: subclass QTabBar and react to the QHoverEvent then subclass QTabWidget to use your custom QTabBar
Hope it helps
-
[quote author="SGaist" date="1374267167"]Hi,
Just a quick idea: subclass QTabBar and react to the QHoverEvent then subclass QTabWidget to use your custom QTabBar
Hope it helps[/quote]
I implement in this way
def mouseHoverOnTabBar(self): self.tabBar=self.tabWidget.tabBar() self.tabBar.setMouseTracking(True) self.tabBar.installEventFilter(self) def eventFilter(self, obj, event): if obj == self.tabBar: if event.type() == QEvent.MouseMove: index=self.tabBar.tabAt(event.pos()) self.tabBar.setCurrentIndex (index) return True return super().eventFilter(obj, event)
-
Right, didn't thought of the eventFilter... Good one !