完善提问模块
This commit is contained in:
0
ui/components/__init__.py
Normal file
0
ui/components/__init__.py
Normal file
@@ -1,4 +1,11 @@
|
||||
from PySide6.QtWidgets import QFrame
|
||||
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):
|
||||
@@ -7,3 +14,44 @@ class Widget(QFrame):
|
||||
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
|
||||
|
||||
16
ui/components/window.py
Normal file
16
ui/components/window.py
Normal file
@@ -0,0 +1,16 @@
|
||||
from PySide6.QtWidgets import QHBoxLayout
|
||||
from qfluentwidgets import FluentTitleBar
|
||||
from qfluentwidgets.window.fluent_window import FluentWindowBase
|
||||
|
||||
|
||||
class MyWindow(FluentWindowBase):
|
||||
def __init__(self, parent=None):
|
||||
super().__init__(parent)
|
||||
self.setTitleBar(FluentTitleBar(self))
|
||||
|
||||
self.widgetLayout = QHBoxLayout(self)
|
||||
self.widgetLayout.setContentsMargins(0, 48, 0, 0)
|
||||
self.hBoxLayout.addLayout(self.widgetLayout)
|
||||
|
||||
self.titleBar.raise_()
|
||||
self.showMaximized()
|
||||
Reference in New Issue
Block a user