📜  PyQt5 - 试管进度条

📅  最后修改于: 2022-05-13 01:55:15.301000             🧑  作者: Mango

PyQt5 - 试管进度条

在本文中,我们将看到如何创建试管形状的进度条。基本上试管形状的进度条是垂直的进度条,底部有圆边。下面是试管进度条的表示。

为了在进度条和进度条条上创建圆底,下面是样式表代码。

QProgressBar
{
border: 1px solid black;
border-bottom-right-radius: 15px;
border-bottom-left-radius: 15px;
}
QProgressBar::chunk 
{
border-bottom-right-radius: 14px;
border-bottom-left-radius: 14px;
background : lightgreen;
}      

下面是实现。

# 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(250, 90, 30, 200)
  
        # set value to progress bar
        bar.setValue(40)
  
        # setting alignment to center
        bar.setAlignment(Qt.AlignCenter)
  
        # setting orientation to vertical
        bar.setOrientation(QtCore.Qt.Vertical)
  
        # setting rounder border at the bottom
        # setting rounded border to the bottom of bar of progress bar
        # and color
        bar.setStyleSheet("QProgressBar"
                          "{"
                          "border : 1px solid black;"
                          "border-bottom-right-radius: 15px;"
                          "border-bottom-left-radius: 15px;"
                          "}"
                          "QProgressBar::chunk"
                          "{"                         
                            
                          "border-bottom-right-radius: 14px;"
                          "border-bottom-left-radius: 14px;"
                          "background : lightgreen"
                          "}"
                          )
  
  
# create pyqt5 app
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :