from PyQt4.QtGui import *
from PyQt4.QtCore import *
class progressSlider(QSlider):
def __init__(self, orientation, parent=None):
super(progressSlider, self).__init__(orientation, parent)
def mousePressEvent(self, event):
if self.topLevelWidget().mediaObj.state() != 2:
return
new = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width())
self.setValue(new)
self.emit(SIGNAL('sliderMoved(int)'), new)
def mouseMoveEvent(self, event):
if self.topLevelWidget().mediaObj.state() != 2:
return
new = QStyle.sliderValueFromPosition(self.minimum(), self.maximum(), event.x(), self.width())
self.setValue(new)
self.emit(SIGNAL('sliderMoved(int)'), new)
def wheelEvent(self, event):
max = self.maximum()
min = self.minimum()
if event.delta() >= 120:
#滚动3%
new = self.value()+ max*0.03
if new > max:
new = max
self.setValue(new)
self.emit(SIGNAL('sliderMoved(int)'), new)
elif event.delta() <= -120:
new = self.value()- max*0.03
if new < min:
new = min
self.setValue(new)
self.emit(SIGNAL('sliderMoved(int)'), new)
[PyQt] 自定义QSlider支持鼠标点击和滚轮事件
最新推荐文章于 2024-10-14 18:33:15 发布