272 lines
8.5 KiB
Python
272 lines
8.5 KiB
Python
from PyQt6.QtCore import Qt
|
|
from PyQt6.QtWidgets import (
|
|
QSlider, QProxyStyle, QStyle
|
|
)
|
|
from PyQt6.QtGui import QColor
|
|
|
|
class SliderGrooveColorStyle(QProxyStyle):
|
|
def __init__(self, base_style=None, groove_color=QColor("lightblue")):
|
|
super().__init__(base_style)
|
|
self.groove_color = groove_color
|
|
|
|
def drawComplexControl(self, control, option, painter, widget=None):
|
|
if control == QStyle.ComplexControl.CC_Slider and isinstance(widget, QSlider):
|
|
|
|
# Récupérer la zone du groove
|
|
groove_rect = self.subControlRect(
|
|
QStyle.ComplexControl.CC_Slider,
|
|
option,
|
|
QStyle.SubControl.SC_SliderGroove,
|
|
widget
|
|
)
|
|
|
|
# Dessiner notre fond
|
|
painter.save()
|
|
painter.setBrush(self.groove_color)
|
|
painter.setPen(Qt.PenStyle.NoPen)
|
|
painter.drawRect(groove_rect)
|
|
painter.restore()
|
|
|
|
# Puis laisser Qt dessiner normalement (handle etc.)
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
return
|
|
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
|
|
class SliderSubPageColorStyle(QProxyStyle):
|
|
def __init__(self, base_style=None, color=QColor("#4CAF50")):
|
|
super().__init__(base_style)
|
|
self.color = color
|
|
|
|
def drawComplexControl(self, control, option, painter, widget=None):
|
|
if control == QStyle.ComplexControl.CC_Slider and isinstance(widget, QSlider):
|
|
|
|
# Laisser Qt dessiner le slider normalement
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
|
|
# Récupérer les rectangles du groove et du handle
|
|
groove_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderGroove,
|
|
widget
|
|
)
|
|
|
|
handle_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderHandle,
|
|
widget
|
|
)
|
|
|
|
painter.save()
|
|
painter.setBrush(self.color)
|
|
painter.setPen(Qt.PenStyle.NoPen)
|
|
|
|
if widget.orientation() == Qt.Orientation.Horizontal:
|
|
# Partie avant le handle (gauche → centre du handle)
|
|
sub_rect = groove_rect.adjusted(
|
|
0,
|
|
0,
|
|
handle_rect.center().x() - groove_rect.right(),
|
|
0
|
|
)
|
|
else:
|
|
# Vertical (bas → centre du handle)
|
|
sub_rect = groove_rect.adjusted(
|
|
0,
|
|
handle_rect.center().y() - groove_rect.bottom(),
|
|
0,
|
|
0
|
|
)
|
|
|
|
painter.drawRect(sub_rect)
|
|
painter.restore()
|
|
|
|
return
|
|
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
|
|
class SliderAddPageColorStyle(QProxyStyle):
|
|
def __init__(self, base_style=None, color=QColor("#FF9800")):
|
|
super().__init__(base_style)
|
|
self.color = color
|
|
|
|
def drawComplexControl(self, control, option, painter, widget=None):
|
|
if control == QStyle.ComplexControl.CC_Slider and isinstance(widget, QSlider):
|
|
|
|
# Récupérer groove + handle
|
|
groove_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderGroove,
|
|
widget
|
|
)
|
|
|
|
handle_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderHandle,
|
|
widget
|
|
)
|
|
|
|
painter.save()
|
|
painter.setBrush(self.color)
|
|
painter.setPen(Qt.PenStyle.NoPen)
|
|
|
|
if widget.orientation() == Qt.Orientation.Horizontal:
|
|
# Partie après le handle (centre → fin)
|
|
add_rect = groove_rect.adjusted(
|
|
handle_rect.center().x() - groove_rect.left(),
|
|
0,
|
|
0,
|
|
0
|
|
)
|
|
else:
|
|
# Vertical (centre → haut)
|
|
add_rect = groove_rect.adjusted(
|
|
0,
|
|
0,
|
|
0,
|
|
handle_rect.center().y() - groove_rect.top()
|
|
)
|
|
|
|
painter.drawRect(add_rect)
|
|
painter.restore()
|
|
|
|
# IMPORTANT : Qt dessine ensuite le handle par-dessus
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
return
|
|
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
|
|
class ThinAddPageLineStyle(QProxyStyle):
|
|
def __init__(self, base_style=None, color=QColor("#E91E63")):
|
|
super().__init__(base_style)
|
|
self.color = color
|
|
|
|
def drawComplexControl(self, control, option, painter, widget=None):
|
|
if control == QStyle.ComplexControl.CC_Slider and isinstance(widget, QSlider):
|
|
|
|
groove_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderGroove,
|
|
widget
|
|
)
|
|
|
|
handle_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderHandle,
|
|
widget
|
|
)
|
|
|
|
painter.save()
|
|
painter.setBrush(self.color)
|
|
painter.setPen(Qt.PenStyle.NoPen)
|
|
|
|
if widget.orientation() == Qt.Orientation.Horizontal:
|
|
# Épaisseur fine (2 px)
|
|
thickness = 2
|
|
|
|
y = groove_rect.center().y() - thickness // 2
|
|
|
|
add_rect = groove_rect.adjusted(
|
|
handle_rect.center().x() - groove_rect.left(),
|
|
0,
|
|
0,
|
|
0
|
|
)
|
|
|
|
add_rect.setTop(y)
|
|
add_rect.setHeight(thickness)
|
|
|
|
else:
|
|
thickness = 2
|
|
|
|
x = groove_rect.center().x() - thickness // 2
|
|
|
|
add_rect = groove_rect.adjusted(
|
|
0,
|
|
0,
|
|
0,
|
|
handle_rect.center().y() - groove_rect.top()
|
|
)
|
|
|
|
add_rect.setLeft(x)
|
|
add_rect.setWidth(thickness)
|
|
|
|
painter.drawRect(add_rect)
|
|
painter.restore()
|
|
|
|
# Dessiner ensuite le slider normalement (handle au-dessus)
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
return
|
|
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
|
|
class ThinSubPageLineStyle(QProxyStyle):
|
|
def __init__(self, base_style=None, color=QColor("#4CAF50")):
|
|
super().__init__(base_style)
|
|
self.color = color
|
|
|
|
def drawComplexControl(self, control, option, painter, widget=None):
|
|
if control == QStyle.ComplexControl.CC_Slider and isinstance(widget, QSlider):
|
|
|
|
groove_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderGroove,
|
|
widget
|
|
)
|
|
|
|
handle_rect = self.subControlRect(
|
|
control,
|
|
option,
|
|
QStyle.SubControl.SC_SliderHandle,
|
|
widget
|
|
)
|
|
|
|
painter.save()
|
|
painter.setBrush(self.color)
|
|
painter.setPen(Qt.PenStyle.NoPen)
|
|
|
|
# Épaisseur fine (ajuste si besoin)
|
|
thickness = 2
|
|
|
|
if widget.orientation() == Qt.Orientation.Horizontal:
|
|
|
|
y = groove_rect.center().y() - thickness // 2
|
|
|
|
sub_rect = groove_rect.adjusted(
|
|
0,
|
|
0,
|
|
handle_rect.center().x() - groove_rect.right(),
|
|
0
|
|
)
|
|
|
|
sub_rect.setTop(y)
|
|
sub_rect.setHeight(thickness)
|
|
|
|
else:
|
|
x = groove_rect.center().x() - thickness // 2
|
|
|
|
sub_rect = groove_rect.adjusted(
|
|
0,
|
|
handle_rect.center().y() - groove_rect.bottom(),
|
|
0,
|
|
0
|
|
)
|
|
|
|
sub_rect.setLeft(x)
|
|
sub_rect.setWidth(thickness)
|
|
|
|
painter.drawRect(sub_rect)
|
|
painter.restore()
|
|
|
|
# Qt redessine le slider (handle au-dessus)
|
|
super().drawComplexControl(control, option, painter, widget)
|
|
return
|
|
|
|
super().drawComplexControl(control, option, painter, widget) |