Progress bar with pyqt

前端 未结 1 1374
北荒
北荒 2021-01-07 01:37

I have a program running many threads, one of them controls the interface and another launches some functions every few seconds. I want the timing thread to update a progres

1条回答
  •  离开以前
    2021-01-07 02:03

    You have to define a signal for the Crono object like this:

    class Crono(QtCore.QThread):
        tick = QtCore.pyqtSignal(int, name="changed") #New style signal
    
        def __init__(self, parent):
            QtCore.QThread.__init__(self,parent)
    
        def checkStatus(self):
            for x in range(1,101):
                self.tick.emit(x)                     
                time.sleep(1)
    

    Then connect it to a slot of the progress bar.

    class WTrainning(wMeta.WMeta, QtGui.QWidget):
    
        def __init__(self):
            super(WTrainning, self).__init__()
            self.crono = Crono()
    
        def createUI(self):
            #Create GUI stuff here
    
            #Connect signal of self.crono to a slot of self.progressBar
            self.crono.tick.connect(self.progressBar.setValue)
    

    What you were doing is connect the SIGNAL valueChanged of the progressBar to its own SLOT setValue

    0 讨论(0)
提交回复
热议问题