34 lines
942 B
Python
34 lines
942 B
Python
# coding:utf-8
|
|
import sys
|
|
from PyQt5.QtCore import Qt
|
|
from PyQt5.QtWidgets import QApplication, QWidget
|
|
|
|
from qfluentwidgets import SwitchButton
|
|
|
|
|
|
class Window(QWidget):
|
|
|
|
def __init__(self, parent=None):
|
|
super().__init__(parent=parent)
|
|
self.resize(160, 80)
|
|
self.switchButton = SwitchButton(parent=self)
|
|
self.switchButton.move(48, 24)
|
|
self.switchButton.checkedChanged.connect(self.onCheckedChanged)
|
|
|
|
def onCheckedChanged(self, isChecked: bool):
|
|
text = 'On' if isChecked else 'Off'
|
|
self.switchButton.setText(text)
|
|
|
|
|
|
if __name__ == '__main__':
|
|
# enable dpi scale
|
|
QApplication.setHighDpiScaleFactorRoundingPolicy(
|
|
Qt.HighDpiScaleFactorRoundingPolicy.PassThrough)
|
|
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling)
|
|
QApplication.setAttribute(Qt.AA_UseHighDpiPixmaps)
|
|
|
|
app = QApplication(sys.argv)
|
|
w = Window()
|
|
w.show()
|
|
sys.exit(app.exec_())
|