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



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


  • Qt Champions 2017

    @Amine-Djeddi
    Hi
    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 :)))


  • Qt Champions 2017

    @Amine-Djeddi
    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.