提交 0ee019b1 编写于 作者: 之一Yo's avatar 之一Yo

重载开关按钮构造函数

上级 f3ac2c87
...@@ -6,6 +6,7 @@ from PyQt5.QtGui import QColor, QPainter ...@@ -6,6 +6,7 @@ from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtWidgets import QHBoxLayout, QLabel, QToolButton, QWidget from PyQt5.QtWidgets import QHBoxLayout, QLabel, QToolButton, QWidget
from ...common.style_sheet import FluentStyleSheet from ...common.style_sheet import FluentStyleSheet
from ...common.overload import singledispatchmethod
class Indicator(QToolButton): class Indicator(QToolButton):
...@@ -129,13 +130,11 @@ class SwitchButton(QWidget): ...@@ -129,13 +130,11 @@ class SwitchButton(QWidget):
checkedChanged = pyqtSignal(bool) checkedChanged = pyqtSignal(bool)
def __init__(self, text='Off', parent=None, indicatorPos=IndicatorPosition.LEFT): @singledispatchmethod
def __init__(self, parent: QWidget = None, indicatorPos=IndicatorPosition.LEFT):
""" """
Parameters Parameters
---------- ----------
text: str
the text of switch button
parent: QWidget parent: QWidget
parent widget parent widget
...@@ -143,14 +142,31 @@ class SwitchButton(QWidget): ...@@ -143,14 +142,31 @@ class SwitchButton(QWidget):
the position of indicator the position of indicator
""" """
super().__init__(parent=parent) super().__init__(parent=parent)
self.text = text self.text = 'Off'
self.__spacing = 12 self.__spacing = 12
self.indicatorPos = indicatorPos self.indicatorPos = indicatorPos
self.hBox = QHBoxLayout(self) self.hBox = QHBoxLayout(self)
self.indicator = Indicator(self) self.indicator = Indicator(self)
self.label = QLabel(text, self) self.label = QLabel(self.text, self)
self.__initWidget() self.__initWidget()
@__init__.register
def _(self, text: str = 'Off', parent: QWidget = None, indicatorPos=IndicatorPosition.LEFT):
"""
Parameters
----------
text: str
the text of switch button
parent: QWidget
parent widget
indicatorPosition: IndicatorPosition
the position of indicator
"""
self.__init__(parent, indicatorPos)
self.setText(text)
def __initWidget(self): def __initWidget(self):
""" initialize widgets """ """ initialize widgets """
self.setAttribute(Qt.WA_StyledBackground) self.setAttribute(Qt.WA_StyledBackground)
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册