There is something about Qt stylesheets that I don't seem to understand. I would simply like to set the background color of a widget to white. But for some reason the background color actually only appears in my widget's children.
I've tried to add self.setAutoFillBackground(True)
to my code, but without success.
I've also tried to palette solution from https://wiki.qt.io/How_to_Change_the_Background_Color_of_QWidget. It worked but only if I don't set a stylesheet, which is needed for the bottom border.
class TopLabelNewProject(qt.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
layout = qt.QHBoxLayout(self)
layout.setContentsMargins(40, 0, 32, 0)
self.setLayout(layout)
self.setFixedHeight(80)
self.setStyleSheet("""
background-color: white;
border-bottom: 1px solid %s;
""" % colors.gray)
self.label = qt.QLabel("Dashboard")
self.label.setStyleSheet("""
QLabel {
font: medium Ubuntu;
font-size: 20px;
color: %s;
}""" % colors.gray_dark)
layout.addWidget(self.label, alignment=qt.Qt.AlignLeft)
self.newProjectButton = Buttons.DefaultButton("New project", self)
layout.addWidget(self.newProjectButton, alignment=qt.Qt.AlignRight)
Note: the Buttons.DefaultButton is just a QPushButton with a custom stylesheet.
This is what I would like to achieve, a white header bar with a label and a button:
But only the label gets a white background.