Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
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
6int main(int argc, char *argv[])
7{
8 QApplication app(argc, argv);
9
10 {
12 QWidget *window = new QWidget;
14 QPushButton *button1 = new QPushButton("One");
16 QPushButton *button2 = new QPushButton("Two");
17 QPushButton *button3 = new QPushButton("Three");
18 QPushButton *button4 = new QPushButton("Four");
19 QPushButton *button5 = new QPushButton("Five");
21
25 layout->addWidget(button1);
26 layout->addWidget(button2);
27 layout->addWidget(button3);
28 layout->addWidget(button4);
29 layout->addWidget(button5);
30
32 window->setWindowTitle("QHBoxLayout");
34 window->show();
36 }
37
38 {
40 QWidget *window = new QWidget;
42 QPushButton *button1 = new QPushButton("One");
44 QPushButton *button2 = new QPushButton("Two");
45 QPushButton *button3 = new QPushButton("Three");
46 QPushButton *button4 = new QPushButton("Four");
47 QPushButton *button5 = new QPushButton("Five");
49
53 layout->addWidget(button1);
54 layout->addWidget(button2);
55 layout->addWidget(button3);
56 layout->addWidget(button4);
57 layout->addWidget(button5);
58
60 window->setWindowTitle("QVBoxLayout");
62 window->show();
64 }
65
66 {
68 QWidget *window = new QWidget;
70 QPushButton *button1 = new QPushButton("One");
72 QPushButton *button2 = new QPushButton("Two");
73 QPushButton *button3 = new QPushButton("Three");
74 QPushButton *button4 = new QPushButton("Four");
75 QPushButton *button5 = new QPushButton("Five");
77
81 layout->addWidget(button1, 0, 0);
82 layout->addWidget(button2, 0, 1);
83 layout->addWidget(button3, 1, 0, 1, 2);
84 layout->addWidget(button4, 2, 0);
85 layout->addWidget(button5, 2, 1);
86
88 window->setWindowTitle("QGridLayout");
90 window->show();
92 }
93
94 {
96 QWidget *window = new QWidget;
99 QPushButton *button1 = new QPushButton("One");
100 QLineEdit *lineEdit1 = new QLineEdit();
103 QPushButton *button2 = new QPushButton("Two");
104 QLineEdit *lineEdit2 = new QLineEdit();
105 QPushButton *button3 = new QPushButton("Three");
106 QLineEdit *lineEdit3 = new QLineEdit();
112 layout->addRow(button1, lineEdit1);
113 layout->addRow(button2, lineEdit2);
114 layout->addRow(button3, lineEdit3);
115
117 window->setWindowTitle("QFormLayout");
119 window->show();
121 }
122
123 {
126 layout->addWidget(formWidget);
129 }
130 return app.exec();
131}
The QApplication class manages the GUI application's control flow and main settings.
static int exec()
Enters the main event loop and waits until exit() is called, then returns the value that was set to e...
void addWidget(QWidget *, int stretch=0, Qt::Alignment alignment=Qt::Alignment())
Adds widget to the end of this box layout, with a stretch factor of stretch and alignment alignment.
The QFormLayout class manages forms of input widgets and their associated labels.
Definition qformlayout.h:18
The QGridLayout class lays out widgets in a grid.
Definition qgridlayout.h:21
The QHBoxLayout class lines up widgets horizontally.
Definition qboxlayout.h:78
The QLineEdit widget is a one-line text editor.
Definition qlineedit.h:28
The QPushButton widget provides a command button.
Definition qpushbutton.h:20
The QVBoxLayout class lines up widgets vertically.
Definition qboxlayout.h:91
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
QPushButton
[1]
int main()
[0]
QVBoxLayout * layout
QApplication app(argc, argv)
[0]
aWidget window() -> setWindowTitle("New Window Title")
[2]
groupBox setLayout(vbox)