Question

After the long visitor status, finally, this is my first post. I create tabs dynamically in my TabWidget(from config). Like; -it is python code, pyqt, answers can be coded c++, dosn’t matter for me :) –

baseWidget = QWidget()
//fill baseWidget with other widgets
window.tabWidget.addTab(baseWidget, _fromUtf8(""))
window.tabWidget.setTabText(window.tabWidget.indexOf(baseWidget), ...)

Then, style via qss, like;

QTabBar::tab {}
QTabBar::tab:selected {}
QTabBar::tab:!selected {}
QTabBar::tab:last {}
QTabBar::tab:first:!selected {}
QTabBar::tab:!selected:hover {}

At this point everything is OK. But, i want to colorize my tabs individually.

How can i achieve this? If it is possible, how can set objectName for a tab?

All post will be appreciated :)

Pas de solution correcte

Autres conseils

Changing base object name won't help, all you are going to do with base object's stylesheet is to change the content background of that panel.

I did a lot of research and tested a few things regarding your problem and it seems like the only solution is to re-implement the QTabWidget paint event.

I tried somethings that I haven't read anywhere else and it gave some weird results, this approach should've worked. If you want to study it and see for yourself:

tabWidget->setCurrentIndex(0);
tabWidget->tabBar()->setStyleSheet("background-color: red;");

tabWidget->setCurrentIndex(1);
tabWidget->tabBar()->setStyleSheet("background-color: blue;");
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top