|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
现有代码1.HuanYing.py如下:
from CustomProgressBar import CustomProgressBar
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1440, 900)
......
# 添加滚动条到布局容器
self.progressBar = CustomProgressBar(parent=self.verticalLayoutWidget_4)
self.progressBar.scrollToCenter()
self.progressBar.startAnimation()
self.verticalLayout_4.addWidget(self.progressBar)
def showSuccessMessage(self):
msgBox = QtWidgets.QMessageBox()
msgBox.setText("登录成功!欢迎使用本报表统计系统!")
msgBox.setWindowTitle("成功")
icon = QtGui.QIcon()
icon.addPixmap(QtGui.QPixmap("success.png"), QtGui.QIcon.Mode.Normal, QtGui.QIcon.State.Off)
msgBox.setWindowIcon(icon)
msgBox.exec()
self.progressBar.setValue(0)
self.progressBar.show() #此处滚动条开始从0滚动到100%
需求: 当滚动条值为100%时,此处如何实现:(1)关闭HuanYing窗体;(2)打开mian窗体。
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
myForm = MyForm()
myForm.show()
sys.exit(app.exec())
代码2. main.py
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName("Form")
Form.resize(1440, 900)
...
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QWidget()
Ui_Form().setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec())
代码3.CustomProgressBar.py
class CustomProgressBar(QProgressBar):
def __init__(self, parent=None):
super().__init__(parent)
self.setStyleSheet(
"""
QProgressBar {
text-align: center;
color: white;
border: none;
background-color: #909090;
height: 20px;
}
QProgressBar::chunk {
background-color: #00A3E0;
}
"""
)
self.setTextVisible(True)
self.setValue(0)
def scrollToCenter(self):
max_value = self.maximum()
if max_value > 0:
self.setValue(max_value)
def startAnimation(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self._animate)
self.timer.start(100)
def _animate(self):
value = self.value() + 2
if value > self.maximum():
value = value % self.maximum()
self.setValue(value)
if value == 100:
self.timer.stop()
class HuanYingWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
layout = QVBoxLayout(self)
self.progressBar = CustomProgressBar()
layout.addWidget(self.progressBar)
self.progressBar.scrollToCenter()
self.progressBar.startAnimation()
self.setLayout(layout)
self.showProgressBarValue()
def showProgressBarValue(self):
value = self.progressBar.value()
print(value)
if value < 100:
QTimer.singleShot(100, self.showProgressBarValue)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = HuanYingWindow()
window.show()
sys.exit(app.exec())
代码3:CustomProgressBar.py
import sys
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QProgressBar, QLabel
from PyQt6.QtCore import QTimer, Qt, pyqtSignal
class CustomProgressBar(QProgressBar):
###
# 添加信号
valueChanged = pyqtSignal(int)
###
def __init__(self, parent=None):
super().__init__(parent)
self.setStyleSheet(
"""
QProgressBar {
text-align: center; /* 将文本居中对齐 */
color: white; /* 设置文本颜色为白色 */
border: none;
background-color: #909090; /* 设置背景色 */
height: 20px; /* 设置进度条高度 */
}
QProgressBar::chunk {
background-color: #00A3E0; /* 设置进度条颜色 */
}
"""
)
self.setTextVisible(True) # 显示进度文本
# self.counter = 0
self.setValue(0)
def scrollToCenter(self):
max_value = self.maximum()
if max_value > 0:
self.setValue(max_value)
def startAnimation(self):
self.timer = QTimer(self)
self.timer.timeout.connect(self._animate)
self.timer.start(100)
def _animate(self):
value = self.value() + 2
if value > self.maximum():
value = value % self.maximum()
self.setValue(value)
###
# 发射信号
self.valueChanged.emit(value)
###
if value == 100:
self.timer.stop()
class HuanYingWindow(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
layout = QVBoxLayout(self)
progressBar = CustomProgressBar()
layout.addWidget(progressBar)
progressBar.scrollToCenter()
progressBar.startAnimation()
self.setLayout(layout)
if __name__ == "__main__":
app = QApplication(sys.argv)
window = HuanYingWindow()
window.show()
sys.exit(app.exec())
回复请注意python格式 |
|