Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. how to create a subclass to rotate a text in a tabbar of tab widget
Forum Updated to NodeBB v4.3 + New Features

how to create a subclass to rotate a text in a tabbar of tab widget

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 1.2k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • sankarapandiyanS Offline
    sankarapandiyanS Offline
    sankarapandiyan
    wrote on last edited by VRonin
    #1

    : error: 'QTabBar* QTabWidget::tabBar() const' is protected

    i tried,

    in cpp file//

     ui->setupUi(this);
     ui->fptabwidget->setStyleSheet("QTabBar::tab{height:160px;width:64}");
        ui->fptabwidget->tabBar()->setStyle(new CustomTabStyle);
    }
    
    

    in header file //

    #include <QProxyStyle>
    #include <QStyleOption>
    #include <QTabBar>
    
    
    namespace Ui {
    class firstpage;
    }
    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::RoundedWest;
            QProxyStyle::drawControl(element, &opt, painter, widget);
            return;
          }
        }
        QProxyStyle::drawControl(element, option, painter, widget);
      }
    };
    

    i have used the proxy style but i dont know how to rotate the text
    the above first line is the error ,

    I think this is cleared by creating a subclass and do the followng code
    but,i am not well clear about the creating the sub class .
    How to do this?

    Thanks in Advance ,....

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      It seems its protected in Qt4.
      So you will need to subclass and surface tabBar()

      class MyTabWidget : public QTabWidget {
        Q_OBJECT
      public:
        explicit MyTabWidget(QWidget* parent = Q_NULLPTR) : QTabWidget(parent)  {}
        QTabBar *GetTabBar() { return tabBar(); }
      };
      
      
      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);
        }
      };
      

      then use promotion to replace with "MyTabWidget"
      http://doc.qt.io/qt-5/designer-using-custom-widgets.html

      and then apply it
      ui->tabWidget->GetTabBar()->setStyle(new CustomTabStyle);

      and hopefully it works the same in older Qt versions.

      1 Reply Last reply
      5
      • sankarapandiyanS Offline
        sankarapandiyanS Offline
        sankarapandiyan
        wrote on last edited by
        #3

        @mrjj thanks a lot

        sankarapandiyanS 1 Reply Last reply
        0
        • sankarapandiyanS sankarapandiyan

          @mrjj thanks a lot

          sankarapandiyanS Offline
          sankarapandiyanS Offline
          sankarapandiyan
          wrote on last edited by
          #4

          @mrjj bro i got a another error !!

          error: 'Q_NULLPTR' was not declared in this scope

          VRoninV 1 Reply Last reply
          0
          • sankarapandiyanS sankarapandiyan

            @mrjj bro i got a another error !!

            error: 'Q_NULLPTR' was not declared in this scope

            VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            @sankarapandiyan a quick google search would have lead you to find the simple "replace Q_NULLPTR with NULL" answer

            "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
            ~Napoleon Bonaparte

            On a crusade to banish setIndexWidget() from the holy land of Qt

            sankarapandiyanS 1 Reply Last reply
            4
            • VRoninV VRonin

              @sankarapandiyan a quick google search would have lead you to find the simple "replace Q_NULLPTR with NULL" answer

              sankarapandiyanS Offline
              sankarapandiyanS Offline
              sankarapandiyan
              wrote on last edited by
              #6

              @VRonin oh !!,So we are using Null instead of Q_NULPTR
              thanks VRonin

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved