0
0
mirror of https://github.com/bec-project/bec_widgets.git synced 2025-07-14 03:31:50 +02:00

fix(toggle): emit state change

This commit is contained in:
2024-08-25 10:57:56 +02:00
parent 8f3824c0e7
commit c4f3308dc0

View File

@ -1,6 +1,6 @@
import sys
from qtpy.QtCore import Property, QEasingCurve, QPointF, QPropertyAnimation, Qt
from qtpy.QtCore import Property, QEasingCurve, QPointF, QPropertyAnimation, Qt, Signal
from qtpy.QtGui import QColor, QPainter
from qtpy.QtWidgets import QApplication, QWidget
@ -10,6 +10,8 @@ class ToggleSwitch(QWidget):
A simple toggle.
"""
enabled = Signal(bool)
def __init__(self, parent=None):
super().__init__(parent)
self.setFixedSize(40, 21)
@ -41,6 +43,7 @@ class ToggleSwitch(QWidget):
self._checked = state
self.update_colors()
self.set_thumb_pos_to_state()
self.enabled.emit(self._checked)
@Property(QPointF)
def thumb_pos(self):
@ -109,9 +112,7 @@ class ToggleSwitch(QWidget):
def mousePressEvent(self, event):
if event.button() == Qt.LeftButton:
self._checked = not self._checked
self.update_colors()
self.animate_thumb()
self.checked = not self.checked
def update_colors(self):