-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathTimerWidget.cpp
More file actions
34 lines (28 loc) · 792 Bytes
/
TimerWidget.cpp
File metadata and controls
34 lines (28 loc) · 792 Bytes
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
#include "TimerWidget.h"
TimerWidget::TimerWidget(QWidget *parent) :
QWidget(parent)
{
QHBoxLayout *hbox = new QHBoxLayout();
label = new QLabel();
hbox->addWidget(label);
hbox->addWidget(new QLabel("ms"));
updateTimer.setInterval(100);
QObject::connect(&updateTimer,SIGNAL(timeout()),this,SLOT(updateLabel()));
updateTimer.stop();
active = false;
setLayout(hbox);
timer = QTime::currentTime();
label->setText("0");
}
void TimerWidget::startTimer(){
timer = QTime::currentTime();
active = true;
updateTimer.start();
}
void TimerWidget::stopTimer(){
active = false;
updateTimer.stop();
}
void TimerWidget::updateLabel(){
label->setText( QString::number(timer.msecsTo(QTime::currentTime()) ));
}