PyQt5 – 进度条的 setInvertedAppearance() 方法
当我们在 PyQt5 中创建进度条时,默认进度,即加载从左到右,但是 PyQt5 允许我们在setInvertedAppearance
方法的帮助下改变它的方向。它以 bool 作为参数并使进度条倒置。
下面是正常进度条和倒置进度条的样子
Syntax : bar.setInvertedAppearance(True)
Argument : It takes bool as argument.
Action performed : It set set the progress bar to inverted appearance.
# 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 alignment to center
bar.setAlignment(Qt.AlignCenter)
# making progress bar inverted
bar.setInvertedAppearance(True)
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :