2 # -*- coding: utf-8 -*-
5 from PyQt4
.QtCore
import QRectF
6 from PyQt4
.QtGui
import QDial
, QPainter
, QPixmap
8 # Imports (Custom Stuff)
11 # Custom Dial, using a pixmap for paiting
12 class PixmapDial(QDial
):
13 def __init__(self
, parent
=None):
14 super(PixmapDial
, self
).__init
__(parent
)
19 self
.use_pixmap
= True
22 def setPixmap(self
, n
):
24 self
.use_pixmap
= False
26 self
.use_pixmap
= True
31 self
.pixmap
= QPixmap(":/bitmaps/dial_%i.png" % (n
))
37 def updateSizes(self
):
38 self
.p_width
= self
.pixmap
.width()
39 self
.p_height
= self
.pixmap
.height()
41 if (self
.p_width
< 1):
44 if (self
.p_height
< 1):
47 self
.p_count
= self
.p_height
/self
.p_width
49 self
.setMinimumSize(self
.p_width
, self
.p_width
)
50 self
.setMaximumSize(self
.p_width
, self
.p_width
)
52 def paintEvent(self
, event
):
54 current
= float(self
.value()-self
.minimum())
55 divider
= float(self
.maximum()-self
.minimum())
60 yper
= int((self
.p_count
-1)*(current
/divider
))
61 ypos
= self
.p_width
*yper
63 target
= QRectF(0.0, 0.0, self
.p_width
, self
.p_width
)
64 source
= QRectF(0.0, ypos
, self
.p_width
, self
.p_width
)
66 painter
= QPainter(self
)
67 painter
.drawPixmap(target
, self
.pixmap
, source
)
70 return QDial
.paintEvent(self
, event
)
72 def resizeEvent(self
, event
):
76 return QDial
.resizeEvent(self
, event
)