My question is similar to what is mentioned in this thread for QPushButtion instead of QLineEdit How to turn QLineEdit background into a Progress Bar.
Here is what I tried to implement which works but looks ugly. Content of main.py:
#!/bin/env python
import sys
from PySide6 import QtWidgets
from main_ui import Ui_Dialog
class Progress(QtWidgets.QDialog):
def __init__(self):
super().__init__()
self.ui = Ui_Dialog()
self.ui.setupUi(self)
self.value = 0
self.ui.btn.clicked.connect(self.updateProgress)
def updateProgress(self):
if self.value > 1:
self.value = 0
self.ui.btn_progress.setStyleSheet('background-color: white')
else:
self.value = self.value + 0.1
self.ui.label.setText(str(self.value))
self.ui.btn_progress.setStyleSheet(('background: qlineargradient(x1:0, y1:0, x2:1, y2:0, stop: 0 #1bb77b, stop: ' +
(str(self.value)) + ' #1bb77b, stop: ' + str(self.value + 0.001) + ' rgba(0, 0, 0, 0), stop: 1 white)'))
app = QtWidgets.QApplication(sys.argv)
window = Progress()
window.show()
app.exec()
Here is the content of main_ui.py file:
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'test_dialog.ui'
##
## Created by: Qt User Interface Compiler version 6.5.1
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QDialog, QLabel, QPushButton,
QSizePolicy, QVBoxLayout, QWidget)
class Ui_Dialog(object):
def setupUi(self, Dialog):
if not Dialog.objectName():
Dialog.setObjectName(u"Dialog")
Dialog.resize(680, 97)
self.verticalLayout = QVBoxLayout(Dialog)
self.verticalLayout.setObjectName(u"verticalLayout")
self.btn_progress = QPushButton(Dialog)
self.btn_progress.setObjectName(u"btn_progress")
self.verticalLayout.addWidget(self.btn_progress)
self.label = QLabel(Dialog)
self.label.setObjectName(u"label")
self.verticalLayout.addWidget(self.label)
self.btn = QPushButton(Dialog)
self.btn.setObjectName(u"btn")
self.verticalLayout.addWidget(self.btn)
self.retranslateUi(Dialog)
QMetaObject.connectSlotsByName(Dialog)
# setupUi
def retranslateUi(self, Dialog):
Dialog.setWindowTitle(QCoreApplication.translate("Dialog", u"Dialog", None))
self.btn_progress.setText(QCoreApplication.translate("Dialog", u"Progress Button", None))
self.label.setText(QCoreApplication.translate("Dialog", u"<html><head/><body><p align=\"center\"><span style=\" font-size:12pt;\">Progress Value : </span></p></body></html>", None))
self.btn.setText(QCoreApplication.translate("Dialog", u"PushButton", None))
# retranslateUi
Is it possible to implement the above code without gradient color so that to make it beautiful?