Qt 6.x
The Qt SDK
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
14{
16 QWidget *firstPageWidget = new QWidget;
17 QWidget *secondPageWidget = new QWidget;
18 QWidget *thirdPageWidget = new QWidget;
19
20 QStackedWidget *stackedWidget = new QStackedWidget;
21 stackedWidget->addWidget(firstPageWidget);
22 stackedWidget->addWidget(secondPageWidget);
23 stackedWidget->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 stackedWidget, &QStackedWidget::setCurrentIndex);
32
36 layout->addWidget(pageComboBox);
38 layout->addWidget(stackedWidget);
41}
42
43int main(int argc, char *argv[])
44{
45 QApplication app(argc, argv);
47 widget.show();
48 return app.exec();
49}
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...
The QComboBox widget is a combined button and popup 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:224
void addWidget(QWidget *w)
Adds widget w to this layout in a manner specific to the layout.
Definition qlayout.cpp:186
QObject * parent() const
Returns a pointer to the parent object.
Definition qobject.h:311
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2823
friend class QWidget
Definition qobject.h:347
The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.
void setCurrentIndex(int index)
int addWidget(QWidget *w)
Appends the given widget to the QStackedWidget and returns the index position.
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.
QLayout * layout() const
Returns the layout manager that is installed on this widget, or \nullptr if no layout manager is inst...
void show()
Shows the widget and its child widgets.
Definition qwidget.cpp:7956
Widget(QWidget *parent=nullptr)
QOpenGLWidget * widget
[1]
int main()
[0]
#define tr(X)
QApplication app(argc, argv)
[0]
IUIAutomationTreeWalker __RPC__deref_out_opt IUIAutomationElement ** parent