使用QThread更改PyQt5小部件的背景

问题描述

我正在使用QThread更改QWidget的背景。但是,有一个问题。当我更改背景时,上一张图像的边缘会很快出现。不久之后,它消失了。我想象然后以错误的方式使用了线程。

Previous image border

这是我的编码:

class Tdd(QtCore.QThread):
    def __init__(self,MainWindow):
        super(Tdd,self).__init__(MainWindow)
        self.MainWindow = MainWindow
    
    def run(self):
        imagens = os.listdir("image")
        for x in imagens:
            QtTest.QTest.qWait(1000)
            self.MainWindow.background.setStyleSheet("QWidget#background {background-image:url(image/" + f"{x}" + ")}")


class MainWindow(QtWidgets.QMainWindow,Ui_MainWindow):
    def __init__(self,*args,**kwargs):
        QtWidgets.QMainWindow.__init__(self,**kwargs)

        self.setupUi(self)
        self.showFullScreen()
        test = Tdd(self)
        test.start()


解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)