Python 将背景图片设置为QTextEdit
如何在python中为QTextEdit窗口设置背景图片 到目前为止,我的班级是这样的:Python 将背景图片设置为QTextEdit,python,background-image,qtextedit,Python,Background Image,Qtextedit,如何在python中为QTextEdit窗口设置背景图片 到目前为止,我的班级是这样的: class MoveText(QtGui.QTextEdit): def __init__(self, example_text): super(MoveText, self).__init__() self.setText(example_text) self.initUI() def initUI(self):
class MoveText(QtGui.QTextEdit):
def __init__(self, example_text):
super(MoveText, self).__init__()
self.setText(example_text)
self.initUI()
def initUI(self):
self.setGeometry(400, 300, 400, 400)
self.setWindowTitle('MoveText')
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.show()
...
我可以通过(www)url设置图片吗?使用:
根据简单的实验,使用外部url的setStyleSheet
似乎不起作用
您可能需要自己下载图像文件。例如:
import urllib
...
url = 'http://qt-project.org/images/qt13a/Qt-logo.png'
with open('background.png', 'wb') as f:
f.write(urllib.urlopen(url).read())
self.setStyleSheet('background-image: url(background.png)')
import urllib
...
url = 'http://qt-project.org/images/qt13a/Qt-logo.png'
with open('background.png', 'wb') as f:
f.write(urllib.urlopen(url).read())
self.setStyleSheet('background-image: url(background.png)')