1
votes

I currently have a QTabWidget that looks like this.The QtabWidget has a QtableView inside it

enter image description here

I wanted to know how I could change the background color of the QtabWidget. I want to maintain my existing stylesheet for the QtabWidget and only add the blue background in the area marked by the red arrows. In short i want to add a background color under the tabs. I currently have a stylesheet that looks like this

QTAB

QTabWidget
{
  /*   min-width:5000em;*/
}


 QTabWidget::tab-bar 
{
     left: 5px; /* move to the right by 5px */
 }


 QTabWidget::pane
 {
     border-top: 1px solid gray;
     border-left: 1px solid gray;
     border-right: 1px solid gray;
     border-bottom: 1px solid gray;
 }

 QTabBar::tab
 {
     background-color: rgb(166, 166, 166);
     min-width: 70px;

     padding-top : 6px;
     padding-bottom : 8px;
     color: rgb(255, 255, 255);
     font: 10pt "Arial";
 }

 QTabBar::tab:selected, QTabBar::tab:hover 
{
     background-color: rgb(127, 127, 127);
 }

 QTabBar::tab:selected 
{
     /*border-color: #9B9B9B;*/
 }

 QTabBar::tab:!selected
 {
     margin-top: 2px; /* make non-selected tabs look smaller */

 }

Any suggestions on how I could add a background color under a tab would be appreciated. Thanks.

2

2 Answers

2
votes

You can use stStyleSheet in the constructor:

ui->YOURWIDGET->setStyleSheet("background-color: YOURCOLOR");
1
votes

In order to make subclass of QWidget works on background color, you need override this function

   def paintEvent(self, event):
      o = QtGui.QStyleOption()
      o.initFrom(self)
      p = QtGui.QPainter(self)
      self.style().drawPrimitive(QtGui.QStyle.PE_Widget, o, p, self)