【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
    @
    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
            else:
                return QTabBar.eventFilter(self, obj, event) #False
        else:
            return QMainWindow.eventFilter(self, obj, event)
    

    @


  • Lifetime Qt Champion

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.