Files
JITToolBox/ui/components/widget.py
2025-06-25 23:18:32 +08:00

58 lines
1.7 KiB
Python

from PySide6.QtWidgets import QApplication, QWidget, QLabel, QPushButton, QVBoxLayout, QFrame
from PySide6.QtCore import QTimer, Qt, Signal
import sys
import random
from qfluentwidgets import DisplayLabel
from module.picker.schema import PickerStudent
class Widget(QFrame):
def __init__(self, key: str, parent=None):
super().__init__(parent=parent)
# 必须给子界面设置全局唯一的对象名
self.setObjectName(key.replace(' ', '-'))
class RollingTextWidget(QWidget):
finishSignal = Signal()
def __init__(self, parent=None):
super().__init__(parent)
self.current_index = 0
self.items = []
self.label = DisplayLabel("", self)
self.label.setAlignment(Qt.AlignCenter)
self.layout = QVBoxLayout()
self.layout.addWidget(self.label)
self.setLayout(self.layout)
self.rolling_timer = QTimer(self)
self.rolling_timer.setInterval(50) # 滚动速度(毫秒)
self.rolling_timer.timeout.connect(self.update_text)
self.stop_timer = QTimer(self)
self.stop_timer.setSingleShot(True)
self.stop_timer.timeout.connect(self.stop_rolling)
def update_text(self):
# 每次显示下一个字符
self.current_index = (self.current_index + 1) % len(self.items)
self.label.setText(self.items[self.current_index].name)
def start_rolling(self):
if not self.rolling_timer.isActive():
self.rolling_timer.start()
self.stop_timer.start(2000) # 2秒后停止滚动
def stop_rolling(self):
self.rolling_timer.stop()
self.finishSignal.emit()
def set_items(self, items: list[PickerStudent]):
self.items = items