我正在通过pyqt5在qt设计器中开发基于python的用户界面。我将背景图像添加到对话框中,并自动在其上的所有小部件上粘贴了背景图像。因此,我尝试更改了小部件的背景颜色,即对话框窗口中的按钮,但只有背景图像可见。
我该怎么做才能仅绘制对话框窗口?我什至尝试将对话框放在后面,但没有帮助。
我试图通过在样式表选项中创建资源文件并在其中提及背景图像来附加背景图像。
我尝试使用setStyleSheet选项,但是它仍然继续将背景图像添加到子代小部件中
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'gui2912.ui'
#
# Created by: PyQt5 UI code generator 5.11.2
#
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(628, 600)
MainWindow.setStyleSheet("#MainWindow {border-image : url( Untitleddesign.png ) 0 0 0 0 stretch stretch; }")
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(MainWindow.sizePolicy().hasHeightForWidth())
MainWindow.setSizePolicy(sizePolicy)
MainWindow.setMinimumSize(QtCore.QSize(628, 600))
MainWindow.setTabShape(QtWidgets.QTabWidget.Rounded)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayoutWidget = QtWidgets.QWidget(self.centralwidget)
self.verticalLayoutWidget.setGeometry(QtCore.QRect(30, 20, 571, 551))
self.verticalLayoutWidget.setObjectName("verticalLayoutWidget")
self.verticalLayout = QtWidgets.QVBoxLayout(self.verticalLayoutWidget)
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.setObjectName("verticalLayout")
self.horizontalWidget = QtWidgets.QWidget(self.verticalLayoutWidget)
self.horizontalWidget.setObjectName("horizontalWidget")
self.horizontalLayout = QtWidgets.QHBoxLayout(self.horizontalWidget)
self.horizontalLayout.setObjectName("horizontalLayout")
self.SaveFile = QtWidgets.QFrame(self.horizontalWidget)
self.SaveFile.setStyleSheet("background-image: url(C:/Users/admin/Desktop/Untitleddesign.png) 0 0 0 0 stretch stretch;")
self.SaveFile.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.SaveFile.setFrameShadow(QtWidgets.QFrame.Raised)
self.SaveFile.setObjectName("SaveFile")
self.layoutWidget = QtWidgets.QWidget(self.SaveFile)
self.layoutWidget.setGeometry(QtCore.QRect(50, 140, 481, 41))
self.layoutWidget.setObjectName("layoutWidget")
self.horizontalLayout_3 = QtWidgets.QHBoxLayout(self.layoutWidget)
self.horizontalLayout_3.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.nameOfFile = QtWidgets.QLineEdit(self.layoutWidget)
self.nameOfFile.setStyleSheet("background-color: rgb(255, 255, 255);")
self.nameOfFile.setText("")
self.nameOfFile.setObjectName("nameOfFile")
self.horizontalLayout_3.addWidget(self.nameOfFile)
self.browse = QtWidgets.QPushButton(self.layoutWidget)
self.browse.setEnabled(True)
self.browse.setStyleSheet("background-color: rgb(234, 239, 255);\n"
"")
self.browse.setObjectName("browse")
self.horizontalLayout_3.addWidget(self.browse)
self.layoutWidget1 = QtWidgets.QWidget(self.SaveFile)
self.layoutWidget1.setGeometry(QtCore.QRect(150, 10, 273, 35))
self.layoutWidget1.setObjectName("layoutWidget1")
self.horizontalLayout_2 = QtWidgets.QHBoxLayout(self.layoutWidget1)
self.horizontalLayout_2.setContentsMargins(10, 10, 5, 5)
self.horizontalLayout_2.setSpacing(10)
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.label = QtWidgets.QLabel(self.layoutWidget1)
self.label.setStyleSheet("")
self.label.setObjectName("label")
self.horizontalLayout_2.addWidget(self.label)
self.comboBox = QtWidgets.QComboBox(self.layoutWidget1)
self.comboBox.setStyleSheet("background-color: rgb(255, 255, 255);")
self.comboBox.setObjectName("comboBox")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.comboBox.addItem("")
self.horizontalLayout_2.addWidget(self.comboBox)
self.translateNow = QtWidgets.QPushButton(self.SaveFile)
self.translateNow.setGeometry(QtCore.QRect(250, 230, 75, 23))
self.translateNow.setStyleSheet("background-color: rgb(234, 239, 255);\n"
"")
self.translateNow.setObjectName("translateNow")
self.insertHere = QtWidgets.QPlainTextEdit(self.SaveFile)
self.insertHere.setGeometry(QtCore.QRect(53, 260, 471, 241))
self.insertHere.setStyleSheet("background-color: rgb(255, 255, 255);")
self.insertHere.setObjectName("insertHere")
self.plainTextEdit = QtWidgets.QPlainTextEdit(self.SaveFile)
self.plainTextEdit.setGeometry(QtCore.QRect(50, 190, 481, 31))
self.plainTextEdit.setStyleSheet("background-color: rgb(255, 255, 255);")
self.plainTextEdit.setObjectName("plainTextEdit")
self.horizontalLayoutWidget = QtWidgets.QWidget(self.SaveFile)
self.horizontalLayoutWidget.setGeometry(QtCore.QRect(190, 100, 172, 31))
self.horizontalLayoutWidget.setObjectName("horizontalLayoutWidget")
self.horizontalLayout_4 = QtWidgets.QHBoxLayout(self.horizontalLayoutWidget)
self.horizontalLayout_4.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.forFile = QtWidgets.QRadioButton(self.horizontalLayoutWidget)
self.forFile.setObjectName("forFile")
self.horizontalLayout_4.addWidget(self.forFile)
self.forString = QtWidgets.QRadioButton(self.horizontalLayoutWidget)
self.forString.setObjectName("forString")
self.horizontalLayout_4.addWidget(self.forString)
self.layoutWidget_2 = QtWidgets.QWidget(self.SaveFile)
self.layoutWidget_2.setGeometry(QtCore.QRect(50, 50, 481, 41))
self.layoutWidget_2.setObjectName("layoutWidget_2")
self.horizontalLayout_5 = QtWidgets.QHBoxLayout(self.layoutWidget_2)
self.horizontalLayout_5.setContentsMargins(0, 0, 0, 0)
self.horizontalLayout_5.setObjectName("horizontalLayout_5")
self.nameOfFile_2 = QtWidgets.QLineEdit(self.layoutWidget_2)
self.nameOfFile_2.setStyleSheet("background-color: rgb(255, 255, 255);")
self.nameOfFile_2.setText("")
self.nameOfFile_2.setObjectName("nameOfFile_2")
self.horizontalLayout_5.addWidget(self.nameOfFile_2)
self.browse_folder = QtWidgets.QPushButton(self.layoutWidget_2)
self.browse_folder.setEnabled(True)
self.browse_folder.setStyleSheet("background-color: rgb(234, 239, 255);\n"
"")
self.browse_folder.setObjectName("browse_folder")
self.horizontalLayout_5.addWidget(self.browse_folder)
self.horizontalLayout.addWidget(self.SaveFile)
self.verticalLayout.addWidget(self.horizontalWidget)
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Inference"))
self.nameOfFile.setPlaceholderText(_translate("MainWindow", "File Name"))
self.browse.setWhatsThis(_translate("MainWindow", "Browse file for translation"))
self.browse.setText(_translate("MainWindow", "Browse File"))
self.label.setText(_translate("MainWindow", "Language Pair for Translation"))
self.comboBox.setItemText(0, _translate("MainWindow", "Hindi to Gujarati"))
self.comboBox.setItemText(1, _translate("MainWindow", "Hindi to Punjabi"))
self.comboBox.setItemText(2, _translate("MainWindow", "Some Other"))
self.translateNow.setToolTip(_translate("MainWindow", "<html><head/><body><p>Enter</p></body></html>"))
self.translateNow.setText(_translate("MainWindow", "Translate"))
self.plainTextEdit.setPlaceholderText(_translate("MainWindow", "Enter the text here..."))
self.forFile.setText(_translate("MainWindow", "File Mode"))
self.forString.setText(_translate("MainWindow", "Enter a string"))
self.nameOfFile_2.setPlaceholderText(_translate("MainWindow", "Fetch the model from here.."))
self.browse_folder.setText(_translate("MainWindow", "Browse Folder"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
我也在python中工作,我正在寻找c ++的答案。
先谢谢您。