1 #-*- coding: utf-8 -*-#
2
3 #-------------------------------------------------------------------------------
4 #Name: 自定义圆形指示灯控件
5 #Description:
6 #Author: lgk
7 #Date: 2018/7/05
8 #-------------------------------------------------------------------------------
9
10 importsys11 from PyQt4.QtGui import *
12 from PyQt4.QtCore import *
13
14 allAttributes = [ 'colorOnBegin', 'colorOnEnd', 'colorOffBegin', 'colorOffEnd', 'colorBorderIn', 'colorBorderOut',15 'radiusBorderOut', 'radiusBorderIn', 'radiusCircle']16 allDefaultVal = [ QColor(0, 240, 0), QColor(0, 160, 0), QColor(0, 68, 0), QColor(0, 28, 0), QColor(140, 140, 140), QColor(100, 100, 100),17 500, 450, 400]18 allLabelNames = [ u'灯亮圆心颜色:', u'灯亮边缘颜色:', u'灯灭圆心颜色:', u'灯灭边缘颜色:', u'边框内测颜色:', u'边框外侧颜色:',19 u'边框外侧半径:', u'边框内侧半径:', u'中间圆灯半径:']20
21 classMyLed(QAbstractButton):22 def __init__(self, parent=None):23 super(MyLed, self).__init__(parent)24 self.initUI()25
26 definitUI(self):27 self.setMinimumSize(24, 24)28 self.setCheckable(True)29 self.scaledSize = 1000.0 #为方便计算,将窗口短边值映射为1000
30 self.setLedDefaultOption()31
32 defsetLedDefaultOption(self):33 for attr, val inzip(allAttributes, allDefaultVal):34 setattr(self, attr, val)35 self.update()36
37 def setLedOption(self, opt='colorOnBegin', val=QColor(0,240,0)):38 ifhasattr(self, opt):39 setattr(self, opt, val)40 self.update()41
42 defresizeEvent(self, evt):43 self.update()44
45 defpaintEvent(self, evt):46 painter =QPainter(self)47 painter.setR