Important: Please read the Qt Code of Conduct -

How to get mouse event from QTabBar

  • Hi
    I want track mouse events occurring in the QTabBar widget inside my QTabWidget but dont see how to do this.

    I would be grateful if someone could provide some hints


  • Lifetime Qt Champion


    You can look for the QTabBar using findChild and install an eventFilter on it

    Hope it helps

  • Hi,

    ich have near the same problem with the Handlich of QTabBar.
    I need do use a mouse-right-click for a special handling by changing the tabs. But I did not find out how to impelent the eventFilter mousePressEvent for that. I can fetch the right click, left clicks, but I am not able to make the same handling by the right click (setting the tab as activ).
    So for what should this be done: I want to change the tab by left click and fill in some 'special' data into that QTabWidget.
    I want to use the right click in the same way, but I want to fill 'all' (different fillings into lists) data into that QTabWidget.
    There are the same elements only different content.

    I hope you could understand my text, I am a nuub in programming and english.

    Thx for help !!!

  • Hi all,

    do I have to open a new discussion to get an answer, ist this here the wrog place ? please give me a hint.


  • Lifetime Qt Champion

    Please practice some patience, waiting 24 to 72 hours before bumping your question is common. Not everybody on this forum lives in the same timezone as you.

    What did you already try ?

  • I tried a lot and now I am so confused ..

    I installed an eventFilter so far so good.
    I am able to get 'QT::LeftButton' and 'QT::RightButton' and the event 'QT::MouseButtonPressed'.

    Now I want to indentify the clicked Tab by index (if possible) in QTabBar (even left or right mousebutton has been used to click) - this is not possible.

    I need the index from the clicked Tab because I want to have the same behavior like we have with the left one. Only some data should be different shown.

    I think I will give up, I have no more Ideas.

  • Lifetime Qt Champion

    You can also subclass QTabBar and set it on your QTabWidget, it will be easier to play with the tabs in there.

Log in to reply