default background color of QTabWidget and QWidget/QGroupBox



  • When I use below code, the default background color is light grey.
    this is the grey color_grey.PNG On the left is the grey color

    self.first_group = QGroupBox("first", self)
    self.first = QGridLayout()
    self.first_group.setLayout(self.first)
    
    self.layout = MyVBoxLayout()
    self.setLayout(self.layout)
    self.layout.addWidget(self.first_group, 0)
    

    However, when I use QTabWidget to combine two QGroupBox together like below, the background is white. How can I still use the default color from QGroupBox? Why does QTabWidget use different default color, since I created several other Widget, they also use light grey.
    this is the white color_white.PNG On the left is the white color.

    self.all_tabs = QTabWidget()
    
    self.first_group = QGroupBox("first", self)
    self.first = QGridLayout()
    self.first_group.setLayout(self.first)
    
    self.second_group = QGroupBox("second", self)
    self.second = QGridLayout()
    self.second_group.setLayout(self.second)
    
    self._classbox.addTab(self.first_group, "1")
    self._classbox.addTab(self.second_group, "2")
    
    self.layout = MyVBoxLayout()
    self.setLayout(self.layout)
    self.layout.addWidget(self.all_tabs, 0)
    

  • Moderators

    @helloworld12345 said in default background color of QTabWidget and QWidget/QGroupBox:

    Why does QTabWidget use different default color, since I created several other Widget, they also use light grey.

    i guess this comes from the platform style, that tab-widgets (e.g. on MS Windows) have white background. A "normal" QWidget has grey background by default when it's a window, if it's a child i guess it's transparent, unless it is overwritten.

    I can't provide you python code. But you can try to set the palette of the tab-widget and set the QPalette::Window role to transparent.

    Read this for more clarification.

    Or set on the content of the tab-widget setAutoFillBackround( true )



  • @helloworld12345 ,

    By default, tabwdgets have white background. Find the background color of groupbox and set that color to tabwidget.



  • @raven-worx

    Great, it works.

    Actually I did try setting QTabWidget setAutoFillBackground(True) previously, but it didn't work.
    Now I tried set VGroupBox setAutoFillBackground(True), then the color changed to light grey which is the exact default color I need.

    Thanks so much, raven-worx.



Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.