QProgressBar barra de progreso

QProgressBar barra de progreso

de importación PyQt5.Qt *
importación sys
tiempo de importación
de clase de ventana (QWidget):
def init (self):
super (). init ()
self.setWindowTitle ( 'QLable的学习')
self.resize (500, 500)
self.setup_ui ()

def setup_ui(self):
    #构造函数
    pb=QProgressBar(self)
    pb.resize(400,40)
    # print(pb.minimum()) #默认最小0
    # print(pb.maximum()) #默认最大100

    #设置范围和当前值
    '''
    最小值setMinimum(self,int)
    最大值setMaximum(self,int)
    范围setRange(0,100)
    '''
    # pb.setMinimum(50)

    pb.setRange(0,100)
    pb.setValue(0)
    pb.setFormat("当前人数%v/总人数 %m")
    pb.setInvertedAppearance(True)
    '''
    %p 百分比
    %v 当前值
    %m 总值
    '''
    #繁忙状态设置setRange(0,0) #不知道文件大小时
    #清零
    # pb.reset()
    btn=QPushButton(self)
    btn.move(200,200)
    btn.setText("测试按钮")
    def test():
        # pb.reset()
        # print(pb.minimum())
        # print(pb.maximum())

        '''重置'''
        # pb.resetFormat()
        pb.setAlignment(Qt.AlignHCenter)
        '''输出文本标签'''
        print(pb.text())
        '''方向Vertical垂直'''
        pb.setOrientation(Qt.Vertical)
        pb.resize(40,400)
        print(pb.isTextVisible())
        pb.setTextDirection(QProgressBar.TopToBottom)
        '''反转'''
        pb.setInvertedAppearance(True)
    # btn.clicked.connect(lambda :pb.reset())
    btn.clicked.connect(test)
    '''文本不可见'''
    # pb.setTextVisible(False)

    '''定时器'''
    timer=QTimer(pb)
    def change_progress():
        if pb.value()==pb.maximum():
            timer.stop()
        time.sleep(0.1)
        pb.setValue(pb.value()+1)
        pass
    timer.timeout.connect(change_progress)
    timer.start()

    pb.valueChanged.connect(lambda val:print("当前的进度值为",val))

si el nombre == ' principal ':
QApplication (sys.argv) = aplicación
de ventana = Ventana ()
window.show ()
sys.exit (app.exec_ ())

Publicado 41 artículos originales · ganado elogios 0 · Vistas 794

Supongo que te gusta

Origin blog.csdn.net/qestion_yz_10086/article/details/104501517
Recomendado
Clasificación