Internal QWidgets of QTabBar's tab?

2019-02-21 00:31发布

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?

标签: c++ qt qtabbar
1条回答
叛逆
2楼-- · 2019-02-21 01:07

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);
查看更多
登录 后发表回答