0

As a follow up of " Hide label text for Qt tabs without setting text to empty string " :

Can I directly access the widgets within the tabs of the QTabBar. I do not mean the corresponding widget which is shown when I select a tab, but the tab's widgets (so in the screenshot below the log label and log icon).

TabBar

I have tried QTabBar::findChildren, but with no success. Any idea?

Community
  • 1
  • 1
Horst Walter
  • 13,663
  • 32
  • 126
  • 228
  • 1
    Did you try the `QTabBar::tabButton()` and `QTabBar::tabIcon()` functions? – vahancho Jul 22 '14 at 20:50
  • `tabIcon` gives me a `const QIcon`, which I can not modify - OK I can set an entirely new icon. `tabButton` always returns `nullptr`: Tried `QWidget *w = this->m_tabBar->tabButton(0, QTabBar::RightSide);` with left and right side. – Horst Walter Jul 22 '14 at 21:14

1 Answers1

2

QTabBar header sections are not actually widgets. They are drawn by QStylePainter inside QTabBar::paintEvent. Thus you can't get access to them. As a workaround you can add a tab with an empty text and set a custom widget to it:

QTabBar *bar = new QTabBar;
bar->addTab("");

QLabel *label = new QLabel("my label");
bar->setTabButton(0, QTabBar::LeftSide, label);
hank
  • 9,553
  • 3
  • 35
  • 50
  • Works well, one caveat. Even the empty text of a tab consumes some space however. So I have some unintended space left there. – Horst Walter Jul 23 '14 at 13:43
  • I think you should be able to adjust that by using a style sheet, try with min-width and padding properties. – pragmanomos Sep 26 '14 at 19:42