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:
@ -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):
|
||||
|
||||
|
Reference in New Issue
Block a user