PyQt5 – 改变进度条的边框
在这篇文章中,我们将看到如何改变或设置进度条的边框。默认情况下,PyQt5为进度条提供了边框,但我们可以根据自己的需要来改变它。下面是默认的边框进度条和风格化的边框进度条的样子。
为了做到这一点,我们必须在setStyleSheet()方法的帮助下改变进度条的CSS样式表。
语法:
bar.setStyleSheet("QProgressBar"
"{"
"border : 4px solid green"
"}")
参数: 它使用字符串作为参数。
执行的动作: 它将在进度条上添加边框。
下面是实现方法
# 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)
# adding border to the progress bar
bar.setStyleSheet("QProgressBar"
"{"
"border : 4px solid green"
"}")
App = QApplication(sys.argv)
# create the instance of our Window
window = Window()
# start the app
sys.exit(App.exec())
输出 :