-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui_components.py
More file actions
42 lines (35 loc) · 1.62 KB
/
ui_components.py
File metadata and controls
42 lines (35 loc) · 1.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from PySide6.QtWidgets import QCheckBox
from PySide6.QtCore import Qt
from PySide6.QtGui import QCursor, QPainter, QColor, QBrush
class ToggleSwitch(QCheckBox):
def __init__(self, parent=None):
super().__init__(parent)
self.setCursor(QCursor(Qt.PointingHandCursor))
# Dimensiones más pequeñas: Ancho 50px, Alto 26px
self.setFixedSize(50, 26)
self.setStyleSheet("""
QCheckBox { spacing: 0px; color: transparent; }
QCheckBox::indicator { width: 50px; height: 26px; border-radius: 13px; }
QCheckBox::indicator:unchecked { background-color: #e6e6e6; border: 2px solid #bdc3c7; }
QCheckBox::indicator:unchecked:hover { background-color: #dcdcdc; }
QCheckBox::indicator:checked { background-color: #2ecc71; border: 2px solid #27ae60; }
""")
def paintEvent(self, event):
super().paintEvent(event)
painter = QPainter(self)
painter.setRenderHint(QPainter.Antialiasing)
# Matemáticas para el círculo (Thumb)
circle_dia = 20 # Diámetro más pequeño
margin = 3 # Margen interno
if self.isChecked():
# Posición derecha (Ancho total 50 - circulo 20 - margen 3 - borde 2)
x_pos = 50 - circle_dia - margin - 2
brush_color = QColor(255, 255, 255)
else:
# Posición izquierda
x_pos = margin + 2
brush_color = QColor(255, 69, 58) # Rojo
painter.setBrush(QBrush(brush_color))
painter.setPen(Qt.NoPen)
painter.drawEllipse(x_pos, margin, circle_dia, circle_dia)
painter.end()