Подскажите плиз, почему из потока не удается выполнить setText со стилем или setStyleSheet?
from PyQt4 import QtCore, QtGui, uic import sys import threading class Get(threading.Thread): def __init__(self, label_message): threading.Thread.__init__(self) self.label_message = label_message def run(self): if win_project.testflag: self.label_message.setText(u'<b style="color:red;">Test 1</b>') win_project.testflag = False else: self.label_message.setText(u'Test 2') self.label_message.setStyleSheet('Qlabel {color: red;}') win_project.testflag = True class MainWindow(QtGui.QMainWindow): def __init__(self): QtGui.QMainWindow.__init__(self) self.training = uic.loadUi("include/test2.ui") self.training.show() self.testflag = False self.connect(self.training.pushButton_get_image, QtCore.SIGNAL("clicked()"), self.GetImage) def GetImage(self): self.th = Get(self.training.label_message) self.th.start() if __name__ == "__main__": app = QtGui.QApplication(sys.argv) win_project = MainWindow() sys.exit(app.exec_())
self.label_message.setText(u'<b style="color:red;">Test 1</b>')
QPixmap: It is not safe to use pixmaps outside the GUI thread
self.label_message.setStyleSheet('Qlabel {color: red;}')
(Parent is QLabel(0x1e00610), parent\'s thread is QThread(0x2361ab8), current thread is QThread(0x24f9ca8) QObject: Cannot create children for a parent that is in a different thread. (Parent is QTextDocument(0x24f9cb8), parent\'s thread is QThread(0x24f9ca8), current thread is QThread(0x2361ab8)