forked from wn0112/PPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volumebutton.py
40 lines (33 loc) · 1.06 KB
/
volumebutton.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from PyQt4 import QtGui, QtCore
class VolumeButton(QtGui.QPushButton):
def __init__(self,parent = None):
super(VolumeButton,self).__init__(parent)
self.status = 0
def loadPixmap(self, pic_name):
self.pixmap = QtGui.QPixmap(pic_name)
self.btn_width = self.pixmap.width()/4
self.btn_height = self.pixmap.height()
self.setFixedSize(self.btn_width, self.btn_height)
def enterEvent(self,event):
self.status = 1
self.update()
def mousePressEvent(self,event):
if(event.button() == QtCore.Qt.LeftButton):
self.mouse_press = True
self.status = 2
self.update()
def mouseReleaseEvent(self,event):
if(self.mouse_press):
self.mouse_press = False
self.status = 0
self.update()
self.clicked.emit(True)
self.released.emit()
def leaveEvent(self,event):
self.status = 0
self.update()
def paintEvent(self,event):
self.painter = QtGui.QPainter()
self.painter.begin(self)
self.painter.drawPixmap(self.rect(), self.pixmap.copy(self.btn_width * self.status, 0, self.btn_width, self.btn_height))
self.painter.end()