How to set the background color of a tab widget in Qt Creator?

Semjon Mössinger picture Semjon Mössinger · Jul 16, 2012 · Viewed 14.6k times · Source

I’m using Qt Creator. In my GUI I use a tab widget. This widget should have the same grey background color as the main window (picture A). I accomplished this by editing the Style Sheet in Qt Designer with:

background-colour: rgb(240, 240, 240);

But now I have two new problems I can’t solve:

  • The buttons (--> Send) are not rounded anymore.
  • The edit boxes’ background color has changed to grey, too.

Befor I changed the Style Sheet the GUI looked like in Picture B.

I also tried

QPalette pal = m_pUi->tabWidget->palette();
pal.setColor(m_pUi->tabWidget->backgroundRole(), Qt::blue);
m_pUi->tabWidget->setPalette(pal);

but this only changes the color behind the tabs, not the entire color of the whole "tab-window-surface".

Do I have to make additional style descriptions or is there an more simple solution?

Picture A - with Style Sheet

Picture A - with Style Sheet

Picture B - without Style Sheet

Picture B - without Style Sheet

Answer

Angie Quijano picture Angie Quijano · Sep 30, 2015

I had the same problem and I discovered that you need to set this attribute to each one of your tabs:

ui->tab->setAutoFillBackground(true);

I'm not sure, but I think that also is necessary set that attribute to the QTabWidget as such.

I hope this help.