Reputation: 1721
I have a Qt interface with a:
My interface is something like this:
BACKGROUND_IMAGE_URL = "D:/image.png"
w = QWidget()
w.setStyleSheet("background-image:" + "url(" + BACKGROUND_IMAGE_URL + ");" + "border:0px")
w.repaint()
w.show()
button = QPushButton("btn1")
button.setStyleSheet("background-color: rgb(255, 255, 255); border:0px")
verticalLayout = QVBoxLayout()
verticalLayout.addWidget(button)
mainLayout = QGridLayout()
mainLayout.addLayout(verticalLayout, 0, 0, 1, 1)
w.setLayout(self.mainLayout)
i.e. a widget with a button. The widget background is an image. The button background should be white, but due to the widget background image, the button stylesheet doesn't show up at all.
I would like the button background to go ON TOP of the widget background image. Any thoughts on how to do this?
Upvotes: 1
Views: 1849
Reputation: 243965
the problem is caused because the background image is going to be applied to all the widgets so the color of the button is not modified. One solution is to apply the background image only to the widget, so we use the .
selector:
w.setStyleSheet(".QWidget{background-image:" + "url(" + BACKGROUND_IMAGE_URL + ");" + "border:0px}")
Upvotes: 2