Horizontal text in QTabWidget

  • Hello!

    I am trying to put the tab text in horizontal. I put the tabs in west orientation but the text appears in vertical like this picture:


    Anybody knows how to put this texts horizontal?

    Thank you very much!!

  • Lifetime Qt Champion

    You can use a QProxyStyle.
    First time is a bit WTF so here an example.

    class CustomTabStyle : public QProxyStyle {
      QSize sizeFromContents(ContentsType type, const QStyleOption* option,
                             const QSize& size, const QWidget* widget) const {
        QSize s = QProxyStyle::sizeFromContents(type, option, size, widget);
        if (type == QStyle::CT_TabBarTab) {
        return s;
      void drawControl(ControlElement element, const QStyleOption* option, QPainter* painter, const QWidget* widget) const {
        if (element == CE_TabBarTabLabel) {
          if (const QStyleOptionTab* tab = qstyleoption_cast<const QStyleOptionTab*>(option)) {
            QStyleOptionTab opt(*tab);
            opt.shape = QTabBar::RoundedNorth;
            QProxyStyle::drawControl(element, &opt, painter, widget);
        QProxyStyle::drawControl(element, option, painter, widget);

    and set it
    ui->tabWidget->tabBar()->setStyle(new CustomTabStyle);

    alt text

  • @mrjj
    hii i'm here again xD
    me too i got the same probleme !! but where to put the code that you shared ?

  • Lifetime Qt Champion

    just put in a .h file and include that where you need to use it
    like create new file and call it TabProxy.h
    past code to it. You will need to add include for QProxyStyle
    and you are ready.

    Then where you use it, #include " TabProxy.h"
    and set on the one you want
    ui->tabWidget->tabBar()->setStyle(new CustomTabStyle);

  • @mrjj

    cool it worked well , thank you very muuuch :)))

  • Lifetime Qt Champion

    np. QProxyStyle is very cool once you find the way around it.

Log in to reply

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