zoukankan      html  css  js  c++  java
  • PyQt5 控件学习(一个一个学习之QProgressBar)

    QProgressBar 的继承图:

    QProgressBar 的描述:

    进度条

    QProgressBar 的继承:

    它是直接继承自QWidget 

    QProgressBar 的功能作用:

    QProgressBar 的功能作用之构造函数:

    from PyQt5.Qt import * #刚开始学习可以这样一下导入
    import sys
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QProgressBar的学习")
            self.resize(400,400)
            self.set_ui()
    
    
        def set_ui(self):
            progressBar = QProgressBar(self)
    
    
    if __name__ == '__main__':
        app =QApplication(sys.argv)
    
        window = Window()
        window.show()
    
        sys.exit(app.exec_())
    View Code

    QProgressBar 的功能作用之设置范围和当前值:

    from PyQt5.Qt import * #刚开始学习可以这样一下导入
    import sys
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QProgressBar的学习")
            self.resize(400,400)
            self.set_ui()
    
    
        def set_ui(self):
            progressBar = QProgressBar(self)
            self.progressBar = progressBar
            print(progressBar.minimum())
            print(progressBar.maximum())
    
            # progressBar.setMaximum(200)
            # progressBar.setRange(0,200)
    
            progressBar.setValue(50)
    
            #繁忙状态
            # progressBar.setRange(0,0 )
    
            btn = QPushButton(self)
            btn.setText("按钮")
            btn.move(0,300)
            btn.clicked.connect(self.btn_clicked_slot)
    
            
        def btn_clicked_slot(self):
            self.progressBar.reset()  
    
            
            
        
    
    if __name__ == '__main__':
        app =QApplication(sys.argv)
    
        window = Window()
        window.show()
    
        sys.exit(app.exec_())
    View Code

    QProgressBar 的功能作用之格式设置:

    from PyQt5.Qt import * #刚开始学习可以这样一下导入
    import sys
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QProgressBar的学习")
            self.resize(400,400)
            self.set_ui()
    
    
        def set_ui(self):
            progressBar = QProgressBar(self)
            self.progressBar = progressBar
    
            progressBar.resize(400,30)
            progressBar.setValue(50)
    
    
            # progressBar.setFormat("当前人数:%v/总人数%m  %p%")
            progressBar.setFormat("当前人数:{}/总人数%m".format(progressBar.value()-progressBar.minimum()))
    
    
    
            btn = QPushButton(self)
            btn.setText("按钮")
            btn.move(0,300)
            btn.clicked.connect(self.btn_clicked_slot)
    
            
        def btn_clicked_slot(self):
            # self.progressBar.resetFormat()
            self.progressBar.setAlignment(Qt.AlignCenter)
            pass
    
    if __name__ == '__main__':
        app =QApplication(sys.argv)
    
        window = Window()
        window.show()
    
        sys.exit(app.exec_())
    View Code

    QProgressBar 的功能作用之文本操作:

    QProgressBar 的功能作用之方向:

    from PyQt5.Qt import * #刚开始学习可以这样一下导入
    import sys
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QProgressBar的学习")
            self.resize(400,400)
            self.set_ui()
    
    
        def set_ui(self):
            progressBar = QProgressBar(self)
            self.progressBar = progressBar
    
            progressBar.resize(400,30)
            progressBar.setValue(50)
    
    
            # progressBar.setFormat("当前人数:%v/总人数%m  %p%")
            progressBar.setFormat("当前人数:{}/总人数%m".format(progressBar.value()-progressBar.minimum()))
    
    
    
            btn = QPushButton(self)
            btn.setText("按钮")
            btn.move(0,300)
            btn.clicked.connect(self.btn_clicked_slot)
    
            
        def btn_clicked_slot(self):
            #文本操作
            # self.progressBar.setTextVisible(False)
            # print(self.progressBar.text())
    
    
            self.progressBar.resize(30,200)
            self.progressBar.setOrientation(Qt.Vertical)
            print(self.progressBar.isVisible())  #True ,但是看不到
            # self.progressBar.setTextDirection(QProgressBar.TopToBottom)
            #也没有显示
            pass
    
            
            
        
    
    if __name__ == '__main__':
        app =QApplication(sys.argv)
    
        window = Window()
        window.show()
    
        sys.exit(app.exec_())
    View Code

    QProgressBar 的功能作用之倒立外观(反转):

    from PyQt5.Qt import * #刚开始学习可以这样一下导入
    import sys
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QProgressBar的学习")
            self.resize(400,400)
            self.set_ui()
    
    
        def set_ui(self):
            progressBar = QProgressBar(self)
            self.progressBar = progressBar
    
            progressBar.resize(400,30)
            progressBar.setValue(50)
    
    
            # progressBar.setFormat("当前人数:%v/总人数%m  %p%")
            progressBar.setFormat("当前人数:{}/总人数%m".format(progressBar.value()-progressBar.minimum()))
    
    
    
            btn = QPushButton(self)
            btn.setText("按钮")
            btn.move(0,300)
            btn.clicked.connect(self.btn_clicked_slot)
    
            
        def btn_clicked_slot(self):
            #反转
            self.progressBar.setInvertedAppearance(True)
            pass
    
            
            
        
    
    if __name__ == '__main__':
        app =QApplication(sys.argv)
    
        window = Window()
        window.show()
    
        sys.exit(app.exec_())
    View Code

    QProgressBar 的信号:

    from PyQt5.Qt import * #刚开始学习可以这样一下导入
    import sys
    
    class Window(QWidget):
        def __init__(self):
            super().__init__()
            self.setWindowTitle("QProgressBar的学习")
            self.resize(400,400)
            self.set_ui()
    
    
        def set_ui(self):
            progressBar = QProgressBar(self)
            self.progressBar = progressBar
    
            progressBar.resize(400,30)
            progressBar.setValue(50)
    
    
            # progressBar.setFormat("当前人数:%v/总人数%m  %p%")
    
    
    
            btn = QPushButton(self)
            btn.setText("按钮")
            btn.move(0,300)
            btn.clicked.connect(self.btn_clicked_slot)
    
            
        def btn_clicked_slot(self):
            timer = QTimer(self.progressBar)  #定时器归 进度条拥有
            def timer_func():
                # print("xxx")
                if self.progressBar.value() >= self.progressBar.maximum():
                    timer.stop()
                self.progressBar.setValue(self.progressBar.value()+20)
                self.progressBar.setFormat("当前人数:{}/总人数%m".format(self.progressBar.value()-self.progressBar.minimum()))
    
    
            timer.timeout.connect(timer_func)  #使用信号
    
            timer.start(1000)  #每隔1s
            #信号 
            self.progressBar.valueChanged.connect(lambda val:print(val))
            
            
        
    
    if __name__ == '__main__':
        app =QApplication(sys.argv)
    
        window = Window()
        window.show()
    
        sys.exit(app.exec_())
    View Code

    总结:

    以上就是QProgressBar ,下面是展示控件中的第四类:对话框样式的展示控件QDialog:

    首先看QErrorMessage :https://www.cnblogs.com/zach0812/p/11398394.html

  • 相关阅读:
    XML错误信息Referenced file contains errors (http://www.springframework.org/schema/beans/spring-beans-4.0.xsd). For more information, right click on the message in the Problems View ...
    Description Resource Path Location Type Cannot change version of project facet Dynamic Web Module to 2.3.
    maven创建web报错Cannot read lifecycle mapping metadata for artifact org.apache.maven.plugins:maven-compiler-plugin:maven-compiler-plugin:3.5.1:runtime Cause: error in opening zip file
    AJAX跨域
    JavaWeb学习总结(转载)
    JDBC学习笔记
    Java动态代理之JDK实现和CGlib实现
    (转)看懂UML类图
    spring boot配置使用fastjson
    python3下django连接mysql数据库
  • 原文地址:https://www.cnblogs.com/zach0812/p/11396235.html
Copyright © 2011-2022 走看看