Doc: Complete Dynamic Layouts Example
- add doc to code - replace old signal/slot syntax - more up-to-date screenshot Task-number: QTBUG-60635 Change-Id: Iec3d2c3d0d8b9c07ccd4446d74d5eca2d88e7e08 Reviewed-by: Paul Wicking <paul.wicking@qt.io> Reviewed-by: Topi Reiniö <topi.reinio@qt.io>
This commit is contained in:
parent
00304eac7b
commit
421cfd9492
BIN
doc/src/images/dynamiclayouts-example.png
Normal file
BIN
doc/src/images/dynamiclayouts-example.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 22 KiB |
@ -34,7 +34,82 @@
|
|||||||
applications. The widget placement depends on whether \c Horizontal or \c
|
applications. The widget placement depends on whether \c Horizontal or \c
|
||||||
Vertical is chosen.
|
Vertical is chosen.
|
||||||
|
|
||||||
|
\borderedimage dynamiclayouts-example.png
|
||||||
For more information, visit the \l{Layout Management} page.
|
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
|
\include examples-run.qdocinc
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
@ -55,12 +55,12 @@
|
|||||||
Dialog::Dialog(QWidget *parent)
|
Dialog::Dialog(QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
{
|
{
|
||||||
createRotableGroupBox();
|
createRotatableGroupBox();
|
||||||
createOptionsGroupBox();
|
createOptionsGroupBox();
|
||||||
createButtonBox();
|
createButtonBox();
|
||||||
|
|
||||||
mainLayout = new QGridLayout;
|
mainLayout = new QGridLayout;
|
||||||
mainLayout->addWidget(rotableGroupBox, 0, 0);
|
mainLayout->addWidget(rotatableGroupBox, 0, 0);
|
||||||
mainLayout->addWidget(optionsGroupBox, 1, 0);
|
mainLayout->addWidget(optionsGroupBox, 1, 0);
|
||||||
mainLayout->addWidget(buttonBox, 2, 0);
|
mainLayout->addWidget(buttonBox, 2, 0);
|
||||||
setLayout(mainLayout);
|
setLayout(mainLayout);
|
||||||
@ -102,17 +102,17 @@ void Dialog::buttonsOrientationChanged(int index)
|
|||||||
|
|
||||||
void Dialog::rotateWidgets()
|
void Dialog::rotateWidgets()
|
||||||
{
|
{
|
||||||
Q_ASSERT(rotableWidgets.count() % 2 == 0);
|
Q_ASSERT(rotatableWidgets.count() % 2 == 0);
|
||||||
|
|
||||||
foreach (QWidget *widget, rotableWidgets)
|
foreach (QWidget *widget, rotatableWidgets)
|
||||||
rotableLayout->removeWidget(widget);
|
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) {
|
for (int i = 0; i < n / 2; ++i) {
|
||||||
rotableLayout->addWidget(rotableWidgets[n - i - 1], 0, i);
|
rotatableLayout->addWidget(rotatableWidgets[n - i - 1], 0, i);
|
||||||
rotableLayout->addWidget(rotableWidgets[i], 1, i);
|
rotatableLayout->addWidget(rotatableWidgets[i], 1, i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -123,23 +123,23 @@ void Dialog::help()
|
|||||||
"dynamically."));
|
"dynamically."));
|
||||||
}
|
}
|
||||||
|
|
||||||
void Dialog::createRotableGroupBox()
|
void Dialog::createRotatableGroupBox()
|
||||||
{
|
{
|
||||||
rotableGroupBox = new QGroupBox(tr("Rotable Widgets"));
|
rotatableGroupBox = new QGroupBox(tr("Rotatable Widgets"));
|
||||||
|
|
||||||
rotableWidgets.enqueue(new QSpinBox);
|
rotatableWidgets.enqueue(new QSpinBox);
|
||||||
rotableWidgets.enqueue(new QSlider);
|
rotatableWidgets.enqueue(new QSlider);
|
||||||
rotableWidgets.enqueue(new QDial);
|
rotatableWidgets.enqueue(new QDial);
|
||||||
rotableWidgets.enqueue(new QProgressBar);
|
rotatableWidgets.enqueue(new QProgressBar);
|
||||||
|
|
||||||
int n = rotableWidgets.count();
|
int n = rotatableWidgets.count();
|
||||||
for (int i = 0; i < n; ++i) {
|
for (int i = 0; i < n; ++i) {
|
||||||
connect(rotableWidgets[i], SIGNAL(valueChanged(int)),
|
connect(rotatableWidgets[i], SIGNAL(valueChanged(int)),
|
||||||
rotableWidgets[(i + 1) % n], SLOT(setValue(int)));
|
rotatableWidgets[(i + 1) % n], SLOT(setValue(int)));
|
||||||
}
|
}
|
||||||
|
|
||||||
rotableLayout = new QGridLayout;
|
rotatableLayout = new QGridLayout;
|
||||||
rotableGroupBox->setLayout(rotableLayout);
|
rotatableGroupBox->setLayout(rotatableLayout);
|
||||||
|
|
||||||
rotateWidgets();
|
rotateWidgets();
|
||||||
}
|
}
|
||||||
@ -154,8 +154,10 @@ void Dialog::createOptionsGroupBox()
|
|||||||
buttonsOrientationComboBox->addItem(tr("Horizontal"), Qt::Horizontal);
|
buttonsOrientationComboBox->addItem(tr("Horizontal"), Qt::Horizontal);
|
||||||
buttonsOrientationComboBox->addItem(tr("Vertical"), Qt::Vertical);
|
buttonsOrientationComboBox->addItem(tr("Vertical"), Qt::Vertical);
|
||||||
|
|
||||||
connect(buttonsOrientationComboBox, SIGNAL(currentIndexChanged(int)),
|
connect(buttonsOrientationComboBox,
|
||||||
this, SLOT(buttonsOrientationChanged(int)));
|
QOverload<int>::of(&QComboBox::currentIndexChanged),
|
||||||
|
this,
|
||||||
|
&Dialog::buttonsOrientationChanged);
|
||||||
|
|
||||||
optionsLayout = new QGridLayout;
|
optionsLayout = new QGridLayout;
|
||||||
optionsLayout->addWidget(buttonsOrientationLabel, 0, 0);
|
optionsLayout->addWidget(buttonsOrientationLabel, 0, 0);
|
||||||
@ -173,7 +175,9 @@ void Dialog::createButtonBox()
|
|||||||
rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),
|
rotateWidgetsButton = buttonBox->addButton(tr("Rotate &Widgets"),
|
||||||
QDialogButtonBox::ActionRole);
|
QDialogButtonBox::ActionRole);
|
||||||
|
|
||||||
connect(rotateWidgetsButton, SIGNAL(clicked()), this, SLOT(rotateWidgets()));
|
connect(rotateWidgetsButton, &QPushButton::clicked, this, &Dialog::rotateWidgets);
|
||||||
connect(closeButton, SIGNAL(clicked()), this, SLOT(close()));
|
connect(closeButton, &QPushButton::clicked, this, &Dialog::close);
|
||||||
connect(helpButton, SIGNAL(clicked()), this, SLOT(help()));
|
connect(helpButton, &QPushButton::clicked, this, &Dialog::help);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -76,12 +76,12 @@ private slots:
|
|||||||
void help();
|
void help();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void createRotableGroupBox();
|
void createRotatableGroupBox();
|
||||||
void createOptionsGroupBox();
|
void createOptionsGroupBox();
|
||||||
void createButtonBox();
|
void createButtonBox();
|
||||||
|
|
||||||
QGroupBox *rotableGroupBox;
|
QGroupBox *rotatableGroupBox;
|
||||||
QQueue<QWidget *> rotableWidgets;
|
QQueue<QWidget *> rotatableWidgets;
|
||||||
|
|
||||||
QGroupBox *optionsGroupBox;
|
QGroupBox *optionsGroupBox;
|
||||||
QLabel *buttonsOrientationLabel;
|
QLabel *buttonsOrientationLabel;
|
||||||
@ -93,7 +93,7 @@ private:
|
|||||||
QPushButton *rotateWidgetsButton;
|
QPushButton *rotateWidgetsButton;
|
||||||
|
|
||||||
QGridLayout *mainLayout;
|
QGridLayout *mainLayout;
|
||||||
QGridLayout *rotableLayout;
|
QGridLayout *rotatableLayout;
|
||||||
QGridLayout *optionsLayout;
|
QGridLayout *optionsLayout;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user