I'm writing a program that should display a chessboard on request from the console, here's skeleton QGraphicsView
class TableView(QGraphicsView):
def __init__(self, item):
super().__init__(item)
self.num = 1
self.Size = self.size() - QtCore.QSize(2, 2)
scene = QtWidgets.QGraphicsScene()
self.setScene(scene)
self.RenderBoard()
def UpdateTable(self, **kwargs):
for key, val in kwargs.items():
setattr(self, key, val)
self.RenderBoard()
def LoadImage(self, path, size, pos=None, flip=False):
print(path, size, pos, flip)
picture = QtGui.QImage(path)
picture = picture.scaled(size)
if flip:
my_transform = QtGui.QTransform()
my_transform.rotate(180)
picture = picture.transformed(my_transform)
pic = QtWidgets.QGraphicsPixmapItem()
pic.setPixmap(QtGui.QPixmap.fromImage(picture))
if pos is not None:
pic.setPos(*pos)
self.scene().addItem(pic)
def RenderBoard(self):
self.scene().clear()
self.LoadImage('img/board.png', self.Size, flip=(self.num % 2 == 0))
def resizeEvent(self, event):
self.Size = self.size() - QtCore.QSize(2, 2)
self.RenderBoard()
super().resizeEvent(event)
The program works and outputs the board, but as soon as I call UpdateTable from QtCore.QThread, which accepts requests from the console, the screen turns white. But, if i change the size of the program, the resizeEvent event is called and the program comes to life again and shows exactly what I wanted.
Do you have any idea what the problem might be?
P.S. the update that I call changes one of the arrays from which the reading occurs during rendering, I printing it during the Update call and during the Resize call, in both cases, it is the same.
Other functions
class UpdaterThread(QtCore.QThread):
def __init__(self, table):
QtCore.QThread.__init__(self)
self.table = table
def run(self):
sleep(1)
self.table.UpdateTable(**{'num': 2})
class Ui_ChessHelper(object):
def setupUi(self, ChessHelper):
self.table = TableView(self.centralwidget)
self.table.setMinimumSize(QtCore.QSize(350, 350))
self.table.setObjectName("table")
self.thread = UpdaterThread(self.table)
self.thread.start()