Created
September 23, 2014 07:41
-
-
Save buzzySmile/a493dfdef129d83ee35c to your computer and use it in GitHub Desktop.
This class supports QLabel blinking with fading effect
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "QBlinkLabelControl.h" | |
QBlinkLabelControl::QBlinkLabelControl(QLabel *label, int _fade_time, int _fade_factor) : | |
m_Label(label), | |
m_iTime(_fade_time), | |
m_iFade(_fade_factor) | |
{ | |
this->setMinimumWidth(70); | |
m_BackgroundColor = QColor(Qt::black); | |
QPalette pal = palette(); | |
pal.setColor(backgroundRole(), m_BackgroundColor); | |
pal.setColor(foregroundRole(), Qt::yellow); | |
m_Label->setPalette(pal); | |
m_Label->setAutoFillBackground(true); | |
timer = new QTimer(); | |
timer->setInterval(m_iTime); | |
connect(timer, SIGNAL(timeout()), | |
this, SLOT(fade_label())); | |
} | |
QBlinkLabelControl::~QBlinkLabelControl() | |
{ | |
} | |
void QBlinkLabelControl::fade_label() | |
{ | |
if ((m_Label->palette().color(backgroundRole()).value()) == 255 ) { | |
timer->stop(); | |
return; | |
} | |
QColor fcolor = m_Label->palette().color(backgroundRole()).darker(m_iFade); | |
QPalette pal = palette(); | |
pal.setColor(backgroundRole(), fcolor); | |
pal.setColor(foregroundRole(), Qt::yellow); | |
m_Label->setPalette(pal); | |
} | |
void QBlinkLabelControl::onChangeState(QBarGraphWidget::Colors _blinkColor) | |
{ | |
timer->stop(); | |
QPalette pal = palette(); | |
pal.setColor(backgroundRole(), _blinkColor); | |
m_Label->setPalette(pal); | |
timer->start(); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <QLabel> | |
#include <QTimer> | |
class QBlinkLabelControl: public QObject | |
{ | |
Q_OBJECT | |
Q_ENUMS(Color) | |
public: | |
QBlinkLabelControl(QLabel *label, int _fade_time=5, int _fade_factor=101); | |
~QBlinkLabelControl(); | |
private: | |
QColor m_BackgroundColor; | |
int m_iTime; | |
int m_iFade; | |
QLabel* m_Label; | |
QTimer *timer; | |
public slots: | |
void onChangeState(QColor _blinkColor); | |
private slots: | |
void fadeLabel(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment