📜  PQt5 - 透明背景进度条

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

PQt5 - 透明背景进度条

在这篇文章中,我们将看到如何使进度条的背景透明,即只有进度条的条是可见的,而背景是完全透明的。为了做到这一点,我们将 alpha 级别(即透明度级别)更改为零,这是使背景完全不可见的最小值。

下面是普通进度条与透明背景进度条的样子

要更改 alpha 级别,我们必须更改进度条的 CSS 样式表,下面是样式表。

QProgressBar
{
background-color : rgba(0, 0, 0, 0);
border : 1px;
}

此样式表代码与setStyleSheet方法一起使用,下面是实现。

# 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 background color to window
        self.setStyleSheet("background-color : yellow")
  
        # 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(30)
  
        # setting alignment to center
        bar.setAlignment(Qt.AlignCenter)
  
        # setting background to invisible
        bar.setStyleSheet("QProgressBar"
                          "{"
                          "background-color : rgba(0, 0, 0, 0);"
                          "border : 1px"
                          "}")
  
  
App = QApplication(sys.argv)
  
# create the instance of our Window
window = Window()
  
# start the app
sys.exit(App.exec())

输出 :