summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-03-15 01:00:11 +0100
committerQt Forward Merge Bot <qt_forward_merge_bot@qt-project.org>2018-03-15 01:00:11 +0100
commit8264e495fa9220c101a8a913701a0b8834a6d58b (patch)
tree069aa1d3efab926991c1edfc5b69a3d9e58dcfba /examples/widgets
parent80f52812f2651e6d427bb3dd2e338b60fb25d48b (diff)
parent8eb3944dac81b8c51d7bac7784204d457551b50c (diff)
Merge remote-tracking branch 'origin/5.11' into dev
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/animation/sub-attaq/mainwindow.cpp9
-rw-r--r--examples/widgets/doc/src/dirview.qdoc36
-rw-r--r--examples/widgets/doc/src/dynamiclayouts.qdoc75
-rw-r--r--examples/widgets/doc/src/graphicsview-flowlayout.qdoc14
-rw-r--r--examples/widgets/graphicsview/flowlayout/main.cpp3
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.cpp54
-rw-r--r--examples/widgets/layouts/dynamiclayouts/dialog.h8
-rw-r--r--examples/widgets/layouts/flowlayout/main.cpp3
8 files changed, 165 insertions, 37 deletions
diff --git a/examples/widgets/animation/sub-attaq/mainwindow.cpp b/examples/widgets/animation/sub-attaq/mainwindow.cpp
index 106404682d..b08a7d9f98 100644
--- a/examples/widgets/animation/sub-attaq/mainwindow.cpp
+++ b/examples/widgets/animation/sub-attaq/mainwindow.cpp
@@ -84,8 +84,13 @@ MainWindow::MainWindow() : QMainWindow(0)
view->setAlignment(Qt::AlignLeft | Qt::AlignTop);
scene->setupScene(newAction, quitAction);
#ifndef QT_NO_OPENGL
- view->setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
+ QGLWidget *glWidget = new QGLWidget(QGLFormat(QGL::SampleBuffers));
+ if (glWidget->context()->isValid()) {
+ view->setViewport(glWidget);
+ } else {
+ qWarning("Unable to create an Open GL context with sample buffers, not using Open GL.");
+ delete glWidget;
+ }
#endif
-
setCentralWidget(view);
}
diff --git a/examples/widgets/doc/src/dirview.qdoc b/examples/widgets/doc/src/dirview.qdoc
index 3d58553b8d..d9a16fa58d 100644
--- a/examples/widgets/doc/src/dirview.qdoc
+++ b/examples/widgets/doc/src/dirview.qdoc
@@ -31,8 +31,38 @@
\ingroup examples-itemviews
\brief This example demonstrates the usage of a tree view.
- \brief The Dir View example shows a tree view onto the local filing system. It uses the
- QFileSystemModel class to provide file and directory information.
+ The Dir View example shows a tree view of the local file
+ system. It uses the QFileSystemModel class to provide file
+ and directory information.
- \image dirview-example.png
+ \borderedimage dirview-example.png
+
+ The example supports a number of command line options.
+ These options include:
+ \list
+ \li Application description
+ \li -help option
+ \li -version option
+ \li if the optionc {-c} is specified, the application will not
+ use custom directory options
+ \endlist
+
+ \quotefromfile itemviews/dirview/main.cpp
+ \skipto QCommandLineParser parser
+ \printuntil parser.positionalArguments
+
+ Declares a QFileSystemModel as data model for viewing
+ the local file system. QFileSystem works with a cache, that is,
+ it is updated continually with QFileSystemWatcher on that folder.
+
+ \skipto QFileSystemModel
+ \printuntil tree.setModel
+
+ Creates a model/view implementation called \c tree
+ for viewing the filesystem.
+
+ \skipto tree.setAnimated(false)
+ \printuntil tree.setWindowTitle
+
+ Sets some formatting options for \c tree.
*/
diff --git a/examples/widgets/doc/src/dynamiclayouts.qdoc b/examples/widgets/doc/src/dynamiclayouts.qdoc
index be59aa6ab9..0b9d43c98e 100644
--- a/examples/widgets/doc/src/dynamiclayouts.qdoc
+++ b/examples/widgets/doc/src/dynamiclayouts.qdoc
@@ -34,7 +34,82 @@
applications. The widget placement depends on whether \c Horizontal or \c
Vertical is chosen.
+ \borderedimage dynamiclayouts-example.png
For more information, visit the \l{Layout Management} page.
+ \section1 Dialog Constructor
+
+ To begin with, the application creates the UI components by calling the
+ following methods:
+
+ \list
+ \li createRotatableGroupBox()
+ \li createOptionsGroupBox()
+ \li createButtonBox()
+ \endlist
+
+ It then adds the UI components to a GridLayout (\c mainLayout).
+
+ Finally, \c Dialog::rotateWidgets() is called.
+
+ \quotefromfile layouts/dynamiclayouts/dialog.cpp
+ \skipuntil createRotatableGroupBox
+ \printuntil setWindowTitle
+
+ \section1 Creating the Main Widgets
+
+ The \c createRotatableGroupBox() method creates a rotatable group box,
+ then adds a series of widgets:
+
+ \list
+ \li QSpinBox
+ \li QSlider
+ \li QDial
+ \li QProgressBar
+ \endlist
+
+ It goes on to add signals and slots to each widget, and assigns
+ a QGridLayout called \a rotatableLayout.
+
+ \skipto Dialog::createRotatableGroupBox
+ \printuntil /^\}/
+
+ \section1 Adding Options
+
+ \c createOptionsGroupBox() creates the following widgets:
+ \list
+ \li \c optionsGroupBox
+ \li \c buttonsOrientationLabel
+ \li \c buttonsOrientationComboBox. The orientation of the ComboBox is either
+ \c horizontal (default value) or \c vertical. These two values
+ are added during the startup of the application. It is not possible
+ to leave the option empty.
+ \endlist
+
+ \skipto Dialog::createOptionsGroupBox()
+ \printuntil /^\}/
+
+ \section1 Adding Buttons
+
+ createButtonBox() constructs a QDialogButtonBox called \c buttonBox
+ to which are added a \c closeButton, a \c helpButton and a
+ \c rotateWidgetsButton.
+ It then assigns a signal and a slot to each button in \c buttonBox.
+
+ \skipto Dialog::createButtonBox()
+ \printuntil /^\}/
+
+
+ \section1 Rotating the Widgets
+
+ Removes the current widgets and activates the next widget.
+
+ \quotefromfile layouts/dynamiclayouts/dialog.cpp
+ \skipto Dialog::rotateWidgets()
+ \printuntil rotatableLayout->addWidget(rotatableWidgets[i]
+ \printuntil }
+ \printuntil }
+
\include examples-run.qdocinc
*/
+
diff --git a/examples/widgets/doc/src/graphicsview-flowlayout.qdoc b/examples/widgets/doc/src/graphicsview-flowlayout.qdoc
index e5080c672d..13819f5499 100644
--- a/examples/widgets/doc/src/graphicsview-flowlayout.qdoc
+++ b/examples/widgets/doc/src/graphicsview-flowlayout.qdoc
@@ -36,5 +36,17 @@
\image graphicsflowlayout-example.png
- See the \l{Flow Layout Example} for a corresponding widget-based example.
+ This example uses a Graphics View to display the widget, which is a more
+ customizable approach than displaying the flow layout in the application
+ window (See \l {Flow Layout Example}).
+
+ Graphics View Flow Layout snippet:
+
+ \snippet graphicsview/flowlayout/main.cpp 1
+
+ Flow Layout Example snippet:
+
+ \snippet layouts/flowlayout/main.cpp 1
+
+
*/
diff --git a/examples/widgets/graphicsview/flowlayout/main.cpp b/examples/widgets/graphicsview/flowlayout/main.cpp
index 850302e175..74c03b9bce 100644
--- a/examples/widgets/graphicsview/flowlayout/main.cpp
+++ b/examples/widgets/graphicsview/flowlayout/main.cpp
@@ -47,7 +47,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
+//! [1]
#include "window.h"
#include <QApplication>
@@ -68,3 +68,4 @@ int main(int argc, char *argv[])
return app.exec();
}
+//! [1]
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.cpp b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
index 080d69204b..f46053372a 100644
--- a/examples/widgets/layouts/dynamiclayouts/dialog.cpp
+++ b/examples/widgets/layouts/dynamiclayouts/dialog.cpp
@@ -55,12 +55,12 @@
Dialog::Dialog(QWidget *parent)
: QDialog(parent)
{
- createRotableGroupBox();
+ createRotatableGroupBox();
createOptionsGroupBox();
createButtonBox();
mainLayout = new QGridLayout;
- mainLayout->addWidget(rotableGroupBox, 0, 0);
+ mainLayout->addWidget(rotatableGroupBox, 0, 0);
mainLayout->addWidget(optionsGroupBox, 1, 0);
mainLayout->addWidget(buttonBox, 2, 0);
setLayout(mainLayout);
@@ -102,17 +102,17 @@ void Dialog::buttonsOrientationChanged(int index)
void Dialog::rotateWidgets()
{
- Q_ASSERT(rotableWidgets.count() % 2 == 0);
+ Q_ASSERT(rotatableWidgets.count() % 2 == 0);
- foreach (QWidget *widget, rotableWidgets)
- rotableLayout->removeWidget(widget);
+ foreach (QWidget *widget, rotatableWidgets)
+ rotatableLayout->removeWidget(widget);
- rotableWidgets.enqueue(rotableWidgets.dequeue());
+ rotatableWidgets.enqueue(rotatableWidgets.dequeue());
- const int n = rotableWidgets.count();
+ const int n = rotatableWidgets.count();
for (int i = 0; i < n / 2; ++i) {
- rotableLayout->addWidget(rotableWidgets[n - i - 1], 0, i);
- rotableLayout->addWidget(rotableWidgets[i], 1, i);
+ rotatableLayout->addWidget(rotatableWidgets[n - i - 1], 0, i);
+ rotatableLayout->addWidget(rotatableWidgets[i], 1, i);
}
}
@@ -123,23 +123,23 @@ void Dialog::help()
"dynamically."));
}
-void Dialog::createRotableGroupBox()
+void Dialog::createRotatableGroupBox()
{
- rotableGroupBox = new QGroupBox(tr("Rotable Widgets"));
+ rotatableGroupBox = new QGroupBox(tr("Rotatable Widgets"));
- rotableWidgets.enqueue(new QSpinBox);
- rotableWidgets.enqueue(new QSlider);
- rotableWidgets.enqueue(new QDial);
- rotableWidgets.enqueue(new QProgressBar);
+ rotatableWidgets.enqueue(new QSpinBox);
+ rotatableWidgets.enqueue(new QSlider);
+ rotatableWidgets.enqueue(new QDial);
+ rotatableWidgets.enqueue(new QProgressBar);
- int n = rotableWidgets.count();
+ int n = rotatableWidgets.count();
for (int i = 0; i < n; ++i) {
- connect(rotableWidgets[i], SIGNAL(valueChanged(int)),
- rotableWidgets[(i + 1) % n], SLOT(setValue(int)));
+ connect(rotatableWidgets[i], SIGNAL(valueChanged(int)),
+ rotatableWidgets[(i + 1) % n], SLOT(setValue(int)));
}
- rotableLayout = new QGridLayout;
- rotableGroupBox->setLayout(rotableLayout);
+ rotatableLayout = new QGridLayout;
+ rotatableGroupBox->setLayout(rotatableLayout);
rotateWidgets();
}
@@ -154,8 +154,10 @@ void Dialog::createOptionsGroupBox()
buttonsOrientationComboBox->addItem(tr("Horizontal"), Qt::Horizontal);
buttonsOrientationComboBox->addItem(tr("Vertical"), Qt::Vertical);
- connect(buttonsOrientationComboBox, SIGNAL(currentIndexChanged(int)),
- this, SLOT(buttonsOrientationChanged(int)));
+ connect(buttonsOrientationComboBox,
+ QOverload<int>::of(&QComboBox::currentIndexChanged),
+ this,
+ &Dialog::buttonsOrientationChanged);
optionsLayout = new QGridLayout;
optionsLayout->addWidget(buttonsOrientationLabel, 0, 0);
@@ -173,7 +175,9 @@ void Dialog::createButtonBox()
rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),
QDialogButtonBox::ActionRole);
- connect(rotateWidgetsButton, SIGNAL(clicked()), this, SLOT(rotateWidgets()));
- connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
- connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
+ connect(rotateWidgetsButton, &QPushButton::clicked, this, &Dialog::rotateWidgets);
+ connect(closeButton, &QPushButton::clicked, this, &Dialog::close);
+ connect(helpButton, &QPushButton::clicked, this, &Dialog::help);
}
+
+
diff --git a/examples/widgets/layouts/dynamiclayouts/dialog.h b/examples/widgets/layouts/dynamiclayouts/dialog.h
index 0ff0c12b38..923a6fe01b 100644
--- a/examples/widgets/layouts/dynamiclayouts/dialog.h
+++ b/examples/widgets/layouts/dynamiclayouts/dialog.h
@@ -76,12 +76,12 @@ private slots:
void help();
private:
- void createRotableGroupBox();
+ void createRotatableGroupBox();
void createOptionsGroupBox();
void createButtonBox();
- QGroupBox *rotableGroupBox;
- QQueue<QWidget *> rotableWidgets;
+ QGroupBox *rotatableGroupBox;
+ QQueue<QWidget *> rotatableWidgets;
QGroupBox *optionsGroupBox;
QLabel *buttonsOrientationLabel;
@@ -93,7 +93,7 @@ private:
QPushButton *rotateWidgetsButton;
QGridLayout *mainLayout;
- QGridLayout *rotableLayout;
+ QGridLayout *rotatableLayout;
QGridLayout *optionsLayout;
};
diff --git a/examples/widgets/layouts/flowlayout/main.cpp b/examples/widgets/layouts/flowlayout/main.cpp
index 99725195e5..bbc78ccda3 100644
--- a/examples/widgets/layouts/flowlayout/main.cpp
+++ b/examples/widgets/layouts/flowlayout/main.cpp
@@ -47,7 +47,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-
+//! [1]
#include <QApplication>
#include "window.h"
@@ -59,3 +59,4 @@ int main(int argc, char *argv[])
window.show();
return app.exec();
}
+//! [1]