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
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
12Widget::Widget(QWidget *parent)
14{
15 //! [0]
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
25 //! [0]
26
27 //! [1]
28 QComboBox *pageComboBox = new QComboBox;
29 pageComboBox->addItem(tr("Page 1"));
30 pageComboBox->addItem(tr("Page 2"));
31 pageComboBox->addItem(tr("Page 3"));
32 connect(pageComboBox, &QComboBox::activated,
33 stackedWidget, &QStackedWidget::setCurrentIndex);
34
35 //! [1]
36
37 //! [2]
38 QVBoxLayout *layout = new QVBoxLayout;
39 //! [2]
40
41 layout->addWidget(pageComboBox);
42
43 //! [3]
44 layout->addWidget(stackedWidget);
45 setLayout(layout);
46 //! [3]
47}
48
49int main(int argc, char *argv[])
50{
51 QApplication app(argc, argv);
52 Widget widget;
53 widget.show();
54 return app.exec();
55}
Widget(QWidget *parent=nullptr)
Definition main.cpp:26
int main(int argc, char *argv[])
[ctor_close]