之前学习白月黑羽的PyQt ProgressBar呈现进度条的时候,不知道如何修改为垂直进度条,增加了一行代码self.progressBar.setOrientation(PySide2.QtCore.Qt.Vertical)
记录一下
import PySide2
from PySide2.QtWidgets import QApplication, QMainWindow, QPushButton, QProgressBar,QMessageBox
from time import sleep
from threading import Thread
from PyQt5 import QtCore, QtGui, QtWidgets
class Stats():
def __init__(self):
self.window = QMainWindow()
self.window.resize(600, 500)# x y
self.window.move(100, 300)
self.progressBar = QProgressBar(self.window)
self.progressBar.resize(50, 300)# x y
self.progressBar.move(200, 30)
self.progressBar.setOrientation(PySide2.QtCore.Qt.Vertical)
# 进度是 0 - 5,
self.progressBar.setRange(0,100)
self.button = QPushButton('统计', self.window)
self.button.move(180, 380)# x y
self.button.clicked.connect(self.handleCalc)
# 统计进行中标记,不能同时做两个统计
self.ongoing = False
def handleCalc(self):
def workerThreadFunc():
x=100
self.ongoing = True
for i in range(1,x+1):
sleep(0.1)
# 设置进度值
self.progressBar.setValue(i)
self.ongoing = False
if self.ongoing:
QMessageBox.warning(
self.window,
'警告','任务进行中,请等待完成')
return
worker = Thread(target=workerThreadFunc)
worker.start()
app = QApplication([])
stats = Stats()
stats.window.show()
app.exec_()