-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtransparentprogressbar.cpp
More file actions
66 lines (56 loc) · 1.56 KB
/
Copy pathtransparentprogressbar.cpp
File metadata and controls
66 lines (56 loc) · 1.56 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include "transparentprogressbar.h"
#include <QStylePainter>
#include <QStyleOptionProgressBarV2>
#include <QPlastiqueStyle>
#include <QPropertyAnimation>
#include <QDebug>
TransparentProgressBar::TransparentProgressBar(QWidget *parent)
: QProgressBar(parent)
, m_initialOpacity(0.6)
{
setAutoFillBackground(false);
setStyle(new QPlastiqueStyle()); // to show text inside of progressbar
setOpacity(m_initialOpacity);
m_opaqueAnimation = new QPropertyAnimation(this, "opacity");
m_opaqueAnimation->setStartValue(1.0);
m_opaqueAnimation->setEndValue(0.0);
connect(this, SIGNAL(valueChanged(int)),
this, SLOT(onValueChanged(int)));
}
TransparentProgressBar::~TransparentProgressBar()
{
}
void TransparentProgressBar::setOpacity(qreal opacity)
{
opacity = qMin(opacity, 1.);
opacity = qMax(0., opacity);
if(m_opacity!=opacity) {
m_opacity = opacity;
update();
}
}
void TransparentProgressBar::onValueChanged(int value)
{
// qDebug() << "onValuChanged:" << value << "/" << maximum();
if(value==0) {
setOpacity(m_initialOpacity);
m_opaqueAnimation->stop();
} else if(value==maximum()) {
m_opaqueAnimation->start();
} else {
m_opaqueAnimation->stop();
}
}
//virtual
void TransparentProgressBar::paintEvent(QPaintEvent* e)
{
QStylePainter paint(this);
paint.setOpacity(m_opacity);
QStyleOptionProgressBarV2 opt;
initStyleOption(&opt);
paint.drawControl(QStyle::CE_ProgressBar, opt);
// QSize oldSize = size();
// resize(QSize(0,0));
// __super::paintEvent(e);
// resize(oldSize);
}