Extending QTabWidget

  • Hi!
    I’d like to tweak my tab widget a bit.
    My goals are to add pin option to QTabWidget tab, like Visual Studio has for example and the other one is to show line edit inside QTabWidget tab to rename it when it’s double clicked. I couldn’t find anything useful in documentation.
    Additionally I’d like to float tabs left and right.

    Thanks in advance!


  • Lifetime Qt Champion


    You could take a look at "QTabBar":http://qt-project.org/doc/qt-4.8/qtabbar.html for a starting point

  • Hi!
    Thanks. It's a starting point.
    But I still could't figure out, how to make some tabs float right and some tabs float left.

  • Lifetime Qt Champion

    What do you mean by "some float right and some float left" ?

  • Like in Visual Studio for example.
    Screenshot bellow.


  • Moderators

    this isn't easy to achieve.
    You could use 2 QTabBars, but then you would have the problem that every tabbar must have a selected tab. So you won't be able to split them up and visually display only 1 selected tab.
    So your only way to go would be to do all the painting yourself. So you will need to study the Qt source code of QTabBar and take over some parts. For painting you will need to initialize the styling options correct, etc.

    Alternatively you can do some hacking with stylesheets and intercepting events to simulate it with multiple toolbars.

    Showing a lineEdit overlay at the correct position on double-click shouldn't be that hard though.

Log in to reply

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