-
Notifications
You must be signed in to change notification settings - Fork 19
/
ToolBar.h
71 lines (60 loc) · 2.19 KB
/
ToolBar.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#pragma once
#include <QComboBox>
#include <QDebug>
#include <QFrame>
#include <QMainWindow>
#include <QPushButton>
#include <QToolBar>
#include <QStyle>
namespace Examples {
class Window1 : public QMainWindow {
Q_OBJECT
public:
Window1() {
stretchableSeparator.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Ignored);
comboBox.addItems({"Red", "Green", "Blue", "Yellow"});
toolBar.addAction(&newAction);
toolBar.addAction(&openAction);
toolBar.addAction(&saveAction);
toolBar.addSeparator();
toolBar.addAction(&printAction);
toolBar.addWidget(&stretchableSeparator);
toolBar.addWidget(&comboBox);
toolBar.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
connect(&newAction, &QAction::triggered, [&] {
qDebug() << "ToolBar/New";
});
connect(&openAction, &QAction::triggered, [&] {
qDebug() << "ToolBar/Open";
});
connect(&saveAction, &QAction::triggered, [&] {
qDebug() << "ToolBar/Save";
});
connect(&printAction, &QAction::triggered, [&] {
qDebug() << "ToolBar/Print";
});
connect(&comboBox, &QComboBox::currentTextChanged, [&] {
qDebug() << comboBox.currentText();
});
toolBar2.addAction(&trashAction);
toolBar2.setToolButtonStyle(Qt::ToolButtonTextBesideIcon);
addToolBar(&toolBar);
addToolBar(Qt::BottomToolBarArea, &toolBar2);
setCentralWidget(&frame);
setUnifiedTitleAndToolBarOnMac(true);
setWindowTitle("Tool bar example");
resize(640, 480);
}
private:
QFrame frame;
QToolBar toolBar {&frame};
QAction newAction {style()->standardIcon(QStyle::StandardPixmap::SP_FileIcon), "&New", &toolBar};
QAction openAction {style()->standardIcon(QStyle::StandardPixmap::SP_DirOpenIcon), "&Open", &toolBar};
QAction saveAction {style()->standardIcon(QStyle::StandardPixmap::SP_DialogSaveButton), "&Save", &toolBar};
QAction printAction {"&Print", &toolBar};
QWidget stretchableSeparator {&frame};
QComboBox comboBox {&frame};
QToolBar toolBar2 {&frame};
QAction trashAction {style()->standardIcon(QStyle::StandardPixmap::SP_TrashIcon), "&Trash", &toolBar2};
};
}