tablevalue.cpp
629 Bytes
#include "tablevalue.h"
#include <QColor>
#include <QtDebug>
void TableValue::setText(const QString &str)
{
QLabel::setText(str);
timer.start(2000);
animationTimer.start(33);
updateColor();
}
void TableValue::updateColor()
{
int remain = timer.remainingTime();
if (remain < 0)
remain = 0;
if (remain > 2000)
remain = 2000;
qreal percentage = ((qreal) remain / 2000) * 0.5;
int b = 255 * percentage;
if (b < 0)
b = 0;
if (b > 255)
b = 255;
setStyleSheet(QString().sprintf("background-color: rgba(255, 0, 0, %d); color: rgb(0, 0, 0)", b));
}