PyQt5 – 进度条的resetFormat()方法

PyQt5 – 进度条的resetFormat()方法

我们知道我们可以使用setFormat方法来设置格式,格式化允许我们为进度条设置格式,如百分比或文本。 resetFormat方法用于清除进度条的所有格式,并将其设置为默认的”%p%”,即百分比值+百分比符号。

语法: bar.resetFormat()

参数: 它不需要参数。

执行的动作: 它将清除该进度条以前的所有格式,并将其设置为默认值。

下面是这个方法的实现。

# importing libraries
from PyQt5.QtWidgets import * 
from PyQt5 import QtCore, QtGui
from PyQt5.QtGui import * 
from PyQt5.QtCore import * 
import sys
  
  
class Window(QMainWindow):
  
    def __init__(self):
        super().__init__()
  
        # setting title
        self.setWindowTitle("Python ")
  
        # setting geometry
        self.setGeometry(100, 100, 600, 400)
  
        # calling method
        self.UiComponents()
  
        # showing all the widgets
        self.show()
  
    # method for widgets
    def UiComponents(self):
        # creating progress bar
        bar = QProgressBar(self)
  
        # setting geometry to progress bar
        bar.setGeometry(200, 100, 200, 30)
  
        # setting the value
        bar.setValue(70)
  
        # setting formatting to display text
        bar.setFormat("Geeks")
  
        # setting alignment to center
        bar.setAlignment(Qt.AlignCenter)
  
        # clearing the format
        # setting it back to defaults
        bar.resetFormat()
  
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :

PyQt5 - 进度条的resetFormat()方法

Python教程

Java教程

Web教程

数据库教程

图形图像教程

大数据教程

开发工具教程

计算机教程