PDA

View Full Version : set different StyleSheet for tabs of the same bar



dotjan
25th July 2012, 10:02
Hi all, struggling trying to figure out how to set different StyleSheet for the tabs of the same bar. Specifically I would need to have some tabs of a size, and some others, actually only the last one at the moment, of a smaller size. However, it seems the last always and only applies, even if I specify it differently. So for example, the following does not solve:


ui->tabWidget->setStyleSheet("QTabBar::tab { width: 120px; }");
ui->tabWidget->setStyleSheet("QTabBar::tab:last { width: 20px; }");


ui->tabWidget->setStyleSheet("QTabBar::tab { width: 120px; }");
ui->tabWidget->setStyleSheet("QTabBar::tab:last { width: 20px; }");

But I am trying with many other different way with no luck. Also doc did not help me with this, unfortunately.

My guess is both the settings have to be specified with the same function.

Thanks for any hint.

yeye_olive
25th July 2012, 10:57
I am not too familiar with style sheets, but it seems to me that you use QWidget::setStyleSheet() as if it were appending new style rules, while in fact it completely replaces the widget's stylesheet. Therefore I would try the following:

ui->tabWidget->setStyleSheet("QTabBar::tab { width: 120px; }\nQTabBar::tab:last { width: 20px; }");
If you ever need to append a rule to an existing stylesheet you can try:

widget->setStyleSheet(widget->styleSheet() + "\nMyNewRule")

high_flyer
25th July 2012, 11:20
To my knowledge you can't style individual tabs in a tab bar, rather - styling the tabs based on state (selected, hovered etc).
QTabBar::tab styles all the tabs in the tab bar.

dotjan
25th July 2012, 12:26
ui->tabWidget->setStyleSheet("QTabBar::tab { width: 120px; }\nQTabBar::tab:last { width: 20px; }");

Yes it works, the new line does the job.

Thanks a lot.


To my knowledge you can't style individual tabs in a tab bar, rather - styling the tabs based on state (selected, hovered etc).
QTabBar::tab styles all the tabs in the tab bar.

I see, actually in my case I am lucky I need a different style for the last tab only, so I can QTabBar::tab:last

Thanks.