-
Notifications
You must be signed in to change notification settings - Fork 19
/
PushButton.h
48 lines (42 loc) · 1.23 KB
/
PushButton.h
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#pragma once
#include <QFrame>
#include <QLabel>
#include <QMainWindow>
#include <QPushButton>
namespace Examples {
class Window1 : public QMainWindow {
Q_OBJECT
public:
Window1() {
pushButton1.setText("button1");
pushButton1.move(50, 50);
connect(&pushButton1, &QPushButton::clicked, [&] {
label1.setText(QString("button1 clicked %1 times").arg(++button1Clicked));
});
pushButton2.setText("button2");
pushButton2.setAutoRepeat(true);
pushButton2.move(50, 100);
pushButton2.resize(200, 75);
connect(&pushButton2, &QPushButton::clicked, [&] {
label2.setText(QString("button2 clicked %1 times").arg(++button2Clicked));
});
label1.setText("button1 clicked 0 times");
label1.move(50, 200);
label1.resize(200, 20);
label2.setText("button2 clicked 0 times");
label2.move(50, 230);
label2.resize(200, 20);
setCentralWidget(&frame);
setWindowTitle("Push button example");
resize(300, 300);
}
private:
QFrame frame;
QPushButton pushButton1 {&frame};
QPushButton pushButton2 {&frame};
QLabel label1 {&frame};
QLabel label2 {&frame};
int button1Clicked = 0;
int button2Clicked = 0;
};
}