Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

【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 ?


  • Lifetime Qt Champion

    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)
    

  • Lifetime Qt Champion

    Right, didn't thought of the eventFilter... Good one !


Log in to reply