forked from keshavbhatt/olivia
-
Notifications
You must be signed in to change notification settings - Fork 0
/
volumeslider.cpp
42 lines (34 loc) · 1.22 KB
/
volumeslider.cpp
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
#include "volumeslider.h"
#include <QStyleOptionSlider>
#include <QPainter>
#include <QDebug>
volumeSlider::volumeSlider(QWidget *parent)
: QSlider(parent)
{
setMouseTracking(true);
}
void volumeSlider::paintEvent(QPaintEvent *ev) {
QStyleOptionSlider opt;
initStyleOption(&opt);
opt.subControls = QStyle::SC_SliderGroove | QStyle::SC_SliderHandle;
if (tickPosition() != NoTicks) {
opt.subControls |= QStyle::SC_SliderTickmarks;
}
QRect groove_rect = style()->subControlRect(QStyle::CC_Slider, &opt, QStyle::SC_SliderGroove, this);
QSlider::paintEvent(ev);
QRect rect(groove_rect.right()-static_cast<int>(groove_rect.width()*0.23), groove_rect.top(),static_cast<int>(groove_rect.width()*0.24), groove_rect.height());//0.6 * groove_rect.width()
QPainter painter(this);
painter.fillRect(rect, QBrush(QColor(42,130,218,80)));
}
void volumeSlider::mouseMoveEvent(QMouseEvent *ev){
emit showToolTip(ev->localPos().toPoint());
QSlider::mouseMoveEvent(ev);
}
void volumeSlider::mousePressEvent(QMouseEvent *ev){
emit setPosition(ev->localPos().toPoint());
QSlider::mousePressEvent(ev);
}
void volumeSlider::wheelEvent(QWheelEvent *e){
//emit showToolTip(QPoint(0,0));
QSlider::wheelEvent(e);
}