Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
layouts.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QtGui>
5#include <QtWidgets>
6
7int main(int argc, char *argv[])
8{
9 QApplication app(argc, argv);
10
11 {
12 //! [0]
13 QWidget *window = new QWidget;
14 //! [0]
15
16 //! [1]
17 QPushButton *button1 = new QPushButton("One");
18 //! [1]
19
20 //! [2]
21 QPushButton *button2 = new QPushButton("Two");
22 QPushButton *button3 = new QPushButton("Three");
23 QPushButton *button4 = new QPushButton("Four");
24 QPushButton *button5 = new QPushButton("Five");
25 //! [2]
26
27 //! [3]
28 QHBoxLayout *layout = new QHBoxLayout(window);
29 //! [3]
30
31 //! [4]
32 layout->addWidget(button1);
33 layout->addWidget(button2);
34 layout->addWidget(button3);
35 layout->addWidget(button4);
36 layout->addWidget(button5);
37
38 //! [4]
39
40 window->setWindowTitle("QHBoxLayout");
41
42 //! [5]
43 window->show();
44 //! [5]
45 }
46
47 {
48 //! [6]
49 QWidget *window = new QWidget;
50 //! [6]
51
52 //! [7]
53 QPushButton *button1 = new QPushButton("One");
54 //! [7]
55
56 //! [8]
57 QPushButton *button2 = new QPushButton("Two");
58 QPushButton *button3 = new QPushButton("Three");
59 QPushButton *button4 = new QPushButton("Four");
60 QPushButton *button5 = new QPushButton("Five");
61 //! [8]
62
63 //! [9]
64 QVBoxLayout *layout = new QVBoxLayout(window);
65 //! [9]
66
67 //! [10]
68 layout->addWidget(button1);
69 layout->addWidget(button2);
70 layout->addWidget(button3);
71 layout->addWidget(button4);
72 layout->addWidget(button5);
73
74 //! [10]
75
76 window->setWindowTitle("QVBoxLayout");
77
78 //! [11]
79 window->show();
80 //! [11]
81 }
82
83 {
84 //! [12]
85 QWidget *window = new QWidget;
86 //! [12]
87
88 //! [13]
89 QPushButton *button1 = new QPushButton("One");
90 //! [13]
91
92 //! [14]
93 QPushButton *button2 = new QPushButton("Two");
94 QPushButton *button3 = new QPushButton("Three");
95 QPushButton *button4 = new QPushButton("Four");
96 QPushButton *button5 = new QPushButton("Five");
97 //! [14]
98
99 //! [15]
100 QGridLayout *layout = new QGridLayout(window);
101 //! [15]
102
103 //! [16]
104 layout->addWidget(button1, 0, 0);
105 layout->addWidget(button2, 0, 1);
106 layout->addWidget(button3, 1, 0, 1, 2);
107 layout->addWidget(button4, 2, 0);
108 layout->addWidget(button5, 2, 1);
109
110 //! [16]
111
112 window->setWindowTitle("QGridLayout");
113
114 //! [17]
115 window->show();
116 //! [17]
117 }
118
119 {
120 //! [18]
121 QWidget *window = new QWidget;
122 //! [18]
123
124 //! [19]
125 QPushButton *button1 = new QPushButton("One");
126 QLineEdit *lineEdit1 = new QLineEdit();
127 //! [19]
128
129 //! [20]
130 QPushButton *button2 = new QPushButton("Two");
131 QLineEdit *lineEdit2 = new QLineEdit();
132 QPushButton *button3 = new QPushButton("Three");
133 QLineEdit *lineEdit3 = new QLineEdit();
134 //! [20]
135
136 //! [21]
137 QFormLayout *layout = new QFormLayout(window);
138 //! [21]
139
140 //! [22]
141 layout->addRow(button1, lineEdit1);
142 layout->addRow(button2, lineEdit2);
143 layout->addRow(button3, lineEdit3);
144
145 //! [22]
146
147 window->setWindowTitle("QFormLayout");
148
149 //! [23]
150 window->show();
151 //! [23]
152 }
153
154 {
155 QWidget *formWidget = new QWidget;
156
157 //! [24]
158 QVBoxLayout *layout = new QVBoxLayout;
159 layout->addWidget(formWidget);
160 formWidget->setLayout(layout);
161 //! [24]
162 }
163 return app.exec();
164}
int main(int argc, char *argv[])
[ctor_close]