0

I want to change 'progress bar' value and text in PyQt5.QtCore.QThread.
Look at the code below, UiControlThread inherits QThread, receiving target method and parameters as input at creation time.

class UiControlThread(QThread):
    def __init__(self, callback, args=None):
        QThread.__init__(self)
        self.callback = callback
        self.args = args
        self.isRunning = False

def run(self):
    self.isRunning = True
    if not self.args == None:
        self.callback(self.args)
    else:
        self.callback()
    self.isRunning = False

And I used UiControlThread class as below.

count = 0
while(True):
    count += 1
    barUpdateTask = UiControlThread(lambda : (
        self.ProgressBar.setValue(count),
        self.ProgressBar.setFormat("Update post in " + str(interval - count) + " seconds")
    ), None)
    barUpdateTask.start()
    waitUntilTaskComplete(barUpdateTask)   #This is same at thread.join()

    #loop control
    if count == n:
        #do somthing
    #end if
    time.sleep(1)
#end while

This code runs on another thread, and I found the error below.

QWidget::repaint: Recursive repaint detected
QBackingStore::endPaint() called with active painter; did you forget to destroy it or call QPainter::end() on it?

May I know what caused the error?

KYH
  • 1
  • 1
  • Qt does not support gui operations of any kind outside the main thread. You should create a single worker thread and then use custom signals to communicate with the main thread (as shown in [this example](https://stackoverflow.com/a/68938869/984421)). – ekhumoro Aug 26 '21 at 13:00

0 Answers0