How set background image for QDialog?
Solved
General and Desktop
-
Hi!
How set background image for QDialog?
It ie not work:self.dialogRegistration = QDialog(self) self.dialogRegistration.setFixedWidth(500) self.dialogRegistration.setMinimumHeight(500) pal = QPalette() background = QImage("./images/Fon.png") background2 = background.scaled(QSize(500, 500)) brush = QBrush(background2) pal.setBrush(QPalette.Background, brush) self.dialogRegistration.setAutoFillBackground(True) self.dialogRegistration.setPalette(pal)
And if do this, then all widgets have background image, but me need set background image only for QDialog
self.dialogRegistration.setStyleSheet("border-image: url(./images/Fon.png) stretch;")
-
It's magic work:
styleSheet = self.dialogRegistration.styleSheet() styleSheet += "; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;" self.dialogRegistration.setStyleSheet(styleSheet) styleSheet.replace("; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;", "") lineEditName.setStyleSheet("background-color: rgb(16,40,84); border-image: url(./images/________.png) stretch;")
-
It's magic work:
styleSheet = self.dialogRegistration.styleSheet() styleSheet += "; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;" self.dialogRegistration.setStyleSheet(styleSheet) styleSheet.replace("; background-color: rgb(16,40,84); border-image: url(./images/Fon.png) stretch;", "") lineEditName.setStyleSheet("background-color: rgb(16,40,84); border-image: url(./images/________.png) stretch;")
@Mikeeeeee if I understand your question then it is preety simple
just use stylesheet withsomeThingWidget.setStylesheet(" #someThingWidget{\ border-image:url("location of image");\ }\ ");
replace location of image with valid url. I would recommend you to use image in resources file.
It's stylesheet way to solve this problem
Thank you