mirror of
https://github.com/QuasarApp/SoundBand.git
synced 2025-04-25 23:04:31 +00:00
control key
This commit is contained in:
parent
85f161f617
commit
77c4fa3c14
@ -2,6 +2,7 @@
|
||||
#include "ui_mainwindow.h"
|
||||
#include <QLabel>
|
||||
#include <QDateTime>
|
||||
#include <QKeyEvent>
|
||||
|
||||
MainWindow::MainWindow(QWidget *parent) :
|
||||
QMainWindow(parent),
|
||||
@ -13,6 +14,19 @@ MainWindow::MainWindow(QWidget *parent) :
|
||||
timer.start();
|
||||
}
|
||||
|
||||
void MainWindow::keyPressEvent(QKeyEvent * key) {
|
||||
|
||||
if (key->key() == Qt::Key_Space) {
|
||||
if (timer.isActive()) {
|
||||
timer.stop();
|
||||
} else {
|
||||
timer.start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
MainWindow::~MainWindow() {
|
||||
delete ui;
|
||||
}
|
||||
@ -21,15 +35,5 @@ void MainWindow::handleTick() {
|
||||
|
||||
auto time = QDateTime::currentMSecsSinceEpoch();
|
||||
|
||||
ui->msec->setText(QString::number( time% 1000));
|
||||
|
||||
if (!(time % 1000)) {
|
||||
if (color == Qt::white) {
|
||||
color = Qt::green;
|
||||
} else {
|
||||
color = Qt::white;
|
||||
}
|
||||
|
||||
ui->color->setStyleSheet(QString("background-color: '%0';").arg(color.name(QColor::HexRgb)));
|
||||
}
|
||||
ui->msec->setText(QString::number(time));
|
||||
}
|
||||
|
@ -14,6 +14,7 @@ class MainWindow : public QMainWindow
|
||||
|
||||
public:
|
||||
explicit MainWindow(QWidget *parent = nullptr);
|
||||
void keyPressEvent(QKeyEvent*);
|
||||
~MainWindow();
|
||||
|
||||
private:
|
||||
|
@ -19,19 +19,21 @@
|
||||
<layout class="QVBoxLayout" name="verticalLayout">
|
||||
<item>
|
||||
<widget class="QLabel" name="msec">
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
<item>
|
||||
<widget class="QLabel" name="color">
|
||||
<property name="styleSheet">
|
||||
<string notr="true">background-color: rgb(138, 226, 52);</string>
|
||||
<string notr="true">font: 48pt "Ubuntu";</string>
|
||||
</property>
|
||||
<property name="text">
|
||||
<string/>
|
||||
</property>
|
||||
<property name="scaledContents">
|
||||
<bool>true</bool>
|
||||
</property>
|
||||
<property name="alignment">
|
||||
<set>Qt::AlignCenter</set>
|
||||
</property>
|
||||
<property name="textInteractionFlags">
|
||||
<set>Qt::LinksAccessibleByMouse|Qt::TextSelectableByKeyboard|Qt::TextSelectableByMouse</set>
|
||||
</property>
|
||||
</widget>
|
||||
</item>
|
||||
</layout>
|
||||
|
Loading…
x
Reference in New Issue
Block a user