Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将背景图片设置为QTextEdit_Python_Background Image_Qtextedit - Fatal编程技术网

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):

如何在python中为QTextEdit窗口设置背景图片

到目前为止,我的班级是这样的:

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)')