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:

    0_1513861703092_b9bc9128-b766-4e0a-a23f-dac1934a1fc0-image.png

    Anybody knows how to put this texts horizontal?

    Thank you very much!!


  • Qt Champions 2017

    Hi
    You can use a QProxyStyle.
    http://doc.qt.io/qt-5/qproxystyle.html
    First time is a bit WTF so here an example.

    class CustomTabStyle : public QProxyStyle {
    public:
      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) {
          s.transpose();
        }
        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);
            return;
          }
        }
        QProxyStyle::drawControl(element, option, painter, widget);
      }
    };
    

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

    alt text


Log in to reply
 

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