Qt提供的带进度显示的只有一个QProgresBar,这个控件要么是加载进度从0~100%,要么是持续的两边滚动;而我想要是倒计时的效果,所以QProgresBar并不满足要求,而Qt重写控件相对于MFC来说简直是轻而易举,所以就整了两种不同的倒计时控件;
QPushButton的绘制部分:
void MProgressButton::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
if (m_iTotalMs > 0) {
QPen pen;
pen.setWidth(6);
pen.setColor(Qt::red);
QPainter painter(this);
painter.setPen(pen);
painter.setRenderHint(QPainter::Antialiasing);
int w = width(), h = height();
int total = (w + h) * 2;
float percent = (m_iRemainMs * 1.0f / m_iTotalMs);
float remain = percent * total;
QLineF line;
if (remain >