title: How to change text alignment in QTabWidget in C++?
body: <p>This is the same question as in:
  <a href="https://stackoverflow.com/questions/3607709/how-to-change-text-alignment-in-qtabwidget">How to change text alignment in QTabWidget?</a></p>
  
  <p>I tried to port that python code into C++ but it doesn't seem to work.</p>
  
  <p>Here is header file:</p>
  
  <pre><code>#include &lt;QTabBar&gt;
  
  class HorizontalTabWidget : public QTabBar
  {
      Q_OBJECT
  public:
      explicit HorizontalTabWidget(QWidget *parent = 0);
  
  protected:
      void paintEvent(QPaintEvent *);
      QSize sizeHint() const;
  };
  </code></pre>
  
  <p>Here is source file:</p>
  
  <pre><code>void HorizontalTabWidget::paintEvent(QPaintEvent *)
  {
      for(int index = 0; index &lt; count(); index++)
      {
          QPainter * painter = new QPainter(this);
          painter-&gt;begin(this);
          painter-&gt;setPen(Qt::blue);
          painter-&gt;setFont(QFont("Arial", 10));
          QRect tabrect = tabRect(index);
          painter-&gt;drawText(tabrect, Qt::AlignVCenter | Qt::TextDontClip, tabText(index));
          painter-&gt;end();
      }
  }
  
  QSize HorizontalTabWidget::sizeHint() const
  {
      return QSize(130, 130);
  }
  </code></pre>
  
  <p>I use it by creating NewTabWidget class that inherits QTabWidget. In the constructor of NewTabWidget I use:</p>
  
  <pre><code>setTabBar(new HorizontalTabWidget);
  </code></pre>
  
  <p>This is done just to be able to use that tabWidget because setTabBar is protected. Here is what I get:
  <img src="https://i.stack.imgur.com/6fKps.png" alt="enter image description here"></p>
  
  <p>What am I missing?</p>
  
  <p><strong>Edit:</strong>
  What I want to create is this but with icons on the top and the labels under the icons (as in Qt Creator):
  <img src="https://i.stack.imgur.com/QBuJ7.png" alt="enter image description here"></p>