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
main.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 <QtWidgets>
5
6class Widget : public QWidget
7{
8public:
9 Widget(QWidget *parent = nullptr);
10};
11
13 : QWidget(parent)
14{
16 QWidget *firstPageWidget = new QWidget;
17 QWidget *secondPageWidget = new QWidget;
18 QWidget *thirdPageWidget = new QWidget;
19
20 QStackedLayout *stackedLayout = new QStackedLayout;
21 stackedLayout->addWidget(firstPageWidget);
22 stackedLayout->addWidget(secondPageWidget);
23 stackedLayout->addWidget(thirdPageWidget);
24
26 QComboBox *pageComboBox = new QComboBox;
27 pageComboBox->addItem(tr("Page 1"));
28 pageComboBox->addItem(tr("Page 2"));
29 pageComboBox->addItem(tr("Page 3"));
30 connect(pageComboBox, &QComboBox::activated,
31 stackedLayout, &QStackedLayout::setCurrentIndex);
33
35 QVBoxLayout *mainLayout = new QVBoxLayout;
37 mainLayout->addWidget(pageComboBox);
39 mainLayout->addLayout(stackedLayout);
40 setLayout(mainLayout);
42}
43
44int main(int argc, char *argv[])
45{
46 QApplication app(argc, argv);
48 widget.show();
49 return app.exec();
50}
51
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.
void addLayout(QLayout *layout, int stretch=0)
Adds layout to the end of the box, with serial stretch factor stretch.
The QComboBox widget combines a button with a dropdown list.
Definition qcombobox.h:24
void activated(int index)
This signal is sent when the user chooses an item in the combobox.
void addItem(const QString &text, const QVariant &userData=QVariant())
Adds an item to the combobox with the given text, and containing the specified userData (stored in th...
Definition qcombobox.h:209
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:346
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
friend class QWidget
Definition qobject.h:382
The QStackedLayout class provides a stack of widgets where only one widget is visible at a time.
void setCurrentIndex(int index)
int addWidget(QWidget *w)
Adds the given widget to the end of this layout and returns the index position of the widget.
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
void setLayout(QLayout *)
Sets the layout manager for this widget to layout.
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7875
Widget(QWidget *parent=nullptr)
QOpenGLWidget * widget
[1]
int main()
[0]
#define tr(X)
QApplication app(argc, argv)
[0]