1

I try (font-weigth: works, but text-align: does not work):

QTabBar::tab:text{
    font-weight:bold;
    text-align:left;
}

I try, but it was also not working:

QTabBar::tab {
    font-weight:bold;
    text-align:left;
}

My QTabWidget:

<item>
 <widget class="QTabWidget" name="tabWidget">
  <widget class="QWidget" name="tab">
   <attribute name="title">
    <string>Tab 1</string>
   </attribute>
  </widget>
  <widget class="QWidget" name="tab_2">
   <attribute name="title">
    <string>Tab 2</string>
   </attribute>
  </widget>
 </widget>
</item>

I also have not found any "property" (<property name="...">) that aligns the text.

how to use the "QSS" to align the text of the tabs (QTabBar/QTabWidget) ?

Protomen
  • 9,471
  • 9
  • 57
  • 124

3 Answers3

0

I do not think this is supported in the current version of Qt (5.4). You can try using a paint event with QPainter to draw the text onto the tab in the alignment you want.

You could use specific padding and Qt::AlignLeft to get this outcome potentially.

See this post on the Qt forum for more info - https://forum.qt.io/topic/35405/qss-qtabbar-text-align-does-not-work

Protomen
  • 9,471
  • 9
  • 57
  • 124
MozzieJoe
  • 112
  • 12
  • Note https://forum.qt.io/topic/35405/qss-qtabbar-text-align-does-not-work this question is mine :) (I'm the Brcotainer user) – Protomen Apr 09 '15 at 17:36
  • Ahhh okay, makes sense - seemed like a very specific question related to this one. Is there a Qt bug report page for this, as I would probably say this is a bug? – MozzieJoe Apr 10 '15 at 14:50
0

Try setElideMode(Qt::ElideRight);

IKavanagh
  • 6,089
  • 11
  • 42
  • 47
June
  • 41
  • 6
0

As a workaround you can pad the title with spaces at the end, use setElideMode(Qt::ElideRight) and use a custom QTabBar with reimplemented sizeHint() to avoid stretched tabs:

QSize TabBar::tabSizeHint(int index) const {
    QSize size = QTabBar::tabSizeHint(index);
    size.setWidth(250);
    return size;
}
elsamuko
  • 668
  • 6
  • 16