更新iO面板控制逻辑和其他bug

This commit is contained in:
Gogs
2024-11-02 15:50:58 +08:00
parent 1bfe95ddcb
commit e31f7632e8
12 changed files with 1024 additions and 247 deletions

View File

@ -1,9 +1,10 @@
from PySide6.QtWidgets import QApplication, QWidget, QLabel
from PySide6.QtCore import QPropertyAnimation, QRect, QSize
from PySide6.QtCore import QPropertyAnimation, QRect, QSize, Signal
class ToggleSwitch(QWidget):
def __init__(self, parent=None):
clicked = Signal(int,bool)
def __init__(self,parent=None):
super().__init__(parent)
self.setFixedSize(QSize(60, 30)) # 设置开关整体大小
@ -29,50 +30,44 @@ class ToggleSwitch(QWidget):
# 点击事件
self.mousePressEvent = self.toggle # 绑定点击事件
def init(self,index):
self.index = index
def toggle(self, event):
# 切换开关状态
self.is_on = not self.is_on
# 更新背景颜色和动画位置
# # if self.is_on:
# # print("d")
self.clicked.emit(self.index,not self.is_on)
# # 更新背景颜色和动画位置
# if self.is_on:
# self.background.setStyleSheet("background-color: #4CAF50; border-radius: 15px;")
# self.animation.setStartValue(QRect(2, 2, 26, 26))
# self.animation.setEndValue(QRect(32, 2, 26, 26))
# else:
# self.background.setStyleSheet("background-color: #ccc; border-radius: 15px;")
# self.animation.setStartValue(QRect(32, 2, 26, 26))
# self.animation.setEndValue(QRect(2, 2, 26, 26))
#
# # 开始动画
# self.animation.start()
pass
def change_status(self):
self.is_on = not self.is_on
if self.is_on:
self.background.setStyleSheet("background-color: #4CAF50; border-radius: 15px;")
self.animation.setStartValue(QRect(2, 2, 26, 26))
self.animation.setEndValue(QRect(32, 2, 26, 26))
# self.animation.setStartValue(QRect(2, 2, 26, 26))
# self.animation.setEndValue(QRect(32, 2, 26, 26))
self.circle.move(32, 2) # 初始位置
else:
self.background.setStyleSheet("background-color: #ccc; border-radius: 15px;")
self.animation.setStartValue(QRect(32, 2, 26, 26))
self.animation.setEndValue(QRect(2, 2, 26, 26))
# self.animation.setStartValue(QRect(32, 2, 26, 26))
# self.animation.setEndValue(QRect(2, 2, 26, 26))
self.circle.move(2,2)
# 开始动画
self.animation.start()
#self.animation.start()
class MainWindow(QWidget):
def __init__(self):
super().__init__()
self.setWindowTitle("Toggle Switch Example")
self.setFixedSize(200, 100)
# 创建滑动开关按钮
self.toggle = ToggleSwitch(self)
self.toggle.move(70, 35) # 将开关放置在窗口中间
# 创建状态标签
self.label = QLabel("Switch is OFF", self)
self.label.move(70, 70)
# 连接滑动开关的状态切换
self.toggle.animation.finished.connect(self.update_label)
def update_label(self):
# 更新标签显示的开关状态
if self.toggle.is_on:
self.label.setText("Switch is ON")
else:
self.label.setText("Switch is OFF")
app = QApplication([])
window = MainWindow()
window.show()
app.exec()