pyside6 进度条弹窗 QProgressDialog的使用记录
2024-01-08 11:35:55
import sys
from PySide6.QtWidgets import QPushButton,QLabel,QProgressDialog,QHBoxLayout,QVBoxLayout,QWidget,QApplication,QMainWindow
from PySide6.QtCore import *
class QProgressDialogDemo(QMainWindow):
def __init__(self):
super(QProgressDialogDemo, self).__init__()
#设置窗口大小
self.resize(400, 150)
self.setWindowTitle("QProgressDialogDemo")
btn = QPushButton("开始")
btn.clicked.connect(self.btnClick)
#创建水平布局
layout = QHBoxLayout()
layout.addWidget(btn)
mainFrame = QWidget()
mainFrame.setLayout(layout)
self.setCentralWidget(mainFrame)
def btnClick(self):
elapsed = 200000
#self.progressDialog = QProgressDialog('下载进度','取消',0,elapsed,self)
self.progressDialog = QProgressDialog()
self.progressDialog.setLabelText("wait ...")
self.progressDialog.setRange(0,elapsed)
self.progressDialog.setCancelButton(None)
self.progressDialog.setWindowTitle('QProgressDialog')
self.progressDialog.setStyleSheet(u"QProgressBar::chunk\n"
"{\n"
"border-radius:11px;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:1,y2:0,stop:0 #01FAFF,stop:1 #26B4FF);\n"
"}\n"
"QProgressBar#progressBar\n"
"{\n"
"height:22px;\n"
"text-align:center;/*\u6587\u672c\u4f4d\u7f6e*/\n"
"font-size:14px;\n"
"color:white;\n"
"border-radius:11px;\n"
"background: #1D5573 ;\n"
"}")
self.progressDialog.show()
for val in range(elapsed):
self.progressDialog.setValue(val)
QCoreApplication.processEvents()
if self.progressDialog.wasCanceled():
break
self.progressDialog.setValue(elapsed)
if __name__ == '__main__':
app = QApplication(sys.argv)
main = QProgressDialogDemo()
main.show()
sys.exit(app.exec_())
取消进度条中的calcel按钮
self.progressDialog.setCancelButton(None)
设置进度条的整体样式
self.progressDialog.setStyleSheet(u"QProgressBar::chunk\n"
"{\n"
"border-radius:11px;\n"
"background:qlineargradient(spread:pad,x1:0,y1:0,x2:1,y2:0,stop:0 #01FAFF,stop:1 #26B4FF);\n"
"}\n"
"QProgressBar#progressBar\n"
"{\n"
"height:22px;\n"
"text-align:center;/*\u6587\u672c\u4f4d\u7f6e*/\n"
"font-size:14px;\n"
"color:white;\n"
"border-radius:11px;\n"
"background: #1D5573 ;\n"
"}")
文章来源:https://blog.csdn.net/lixiaofeng0/article/details/135452157
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。 如若内容造成侵权/违法违规/事实不符,请联系我的编程经验分享网邮箱:veading@qq.com进行投诉反馈,一经查实,立即删除!