gpt4 book ai didi

python - PyQt4 图像作为背景

转载 作者:太空宇宙 更新时间:2023-11-04 08:05:34 25 4
gpt4 key购买 nike

我正在使用设计师的下面代码,我试图让 Qwidget 有一个图像作为背景,然后让列表小部件和文本编辑小部件透明。

我遇到的主要问题是,当我使用“表单”的样式表将图像作为背景时,它也会作为列表小部件和文本编辑小部件的背景。我如何让那些保留自己的样式表。

from PyQt4 import QtCore, QtGui

try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s

try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)

class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.setEnabled(True)
Form.resize(854, 667)
Form.setAutoFillBackground(False)
Form.setStyleSheet("background-image: url(test.jpg);")
self.textEdit = QtGui.QTextEdit(Form)
self.textEdit.setGeometry(QtCore.QRect(20, 400, 821, 251))
self.textEdit.setStyleSheet(_fromUtf8("background-color: rgba(255, 255, 255, 102);"))
self.textEdit.setObjectName(_fromUtf8("textEdit"))
self.listWidget = QtGui.QListWidget(Form)
self.listWidget.setGeometry(QtCore.QRect(360, 10, 471, 371))
self.listWidget.setAutoFillBackground(True)
self.listWidget.setStyleSheet(_fromUtf8("background-color: rgba(255, 255, 255, 102);"))
self.listWidget.setObjectName(_fromUtf8("listWidget"))
item = QtGui.QListWidgetItem()
item.setCheckState(QtCore.Qt.Checked)
self.listWidget.addItem(item)
item = QtGui.QListWidgetItem()
item.setCheckState(QtCore.Qt.Checked)
self.listWidget.addItem(item)

self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)

def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
__sortingEnabled = self.listWidget.isSortingEnabled()
self.listWidget.setSortingEnabled(False)
item = self.listWidget.item(0)
item.setText(_translate("Form", "blah blh sdfsaasdfdsfasf", None))
item = self.listWidget.item(1)
item.setText(_translate("Form", "test", None))
self.listWidget.setSortingEnabled(__sortingEnabled)

if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())

谢谢

最佳答案

这对我有用:

    self.text_field = QtGui.QPlainTextEdit(self)
self.text_field.setMinimumSize (480,150)
self.text_field.setStyleSheet("background-image: url(FILENAME); background-attachment: fixed")

关于python - PyQt4 图像作为背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31868790/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com