summaryrefslogtreecommitdiffstats
path: root/examples/widgets
diff options
context:
space:
mode:
authorElias Hautala <Elias.Hautala@qt.io>2022-08-03 11:25:49 +0300
committerElias Hautala <Elias.Hautala@qt.io>2022-08-15 11:22:14 +0300
commit1a6019438881b9aa54cfc8dbd3f8fc06ddc35d67 (patch)
tree9aad1da1e49faedbcc266a6acd398f3d44e8029c /examples/widgets
parentb0576592555f08002d53d1ec78dc991b1a07e2ac (diff)
Sliders: Add function that changes widgets position on layout
Changes the layout to QGridLayout and adds function to change widgets position on the layout depending on the windows aspect ratio. Before this the widgets wouldn't fit on screen when using the example on Android in portrait. Fixes: QTCREATORBUG-27685 Pick-to: 6.2 6.3 6.4 Change-Id: I00009cb6c8c250a8333ac3dfa635f70da4576d5e Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Jani Korteniemi <jani.korteniemi@qt.io>
Diffstat (limited to 'examples/widgets')
-rw-r--r--examples/widgets/widgets/sliders/window.cpp41
-rw-r--r--examples/widgets/widgets/sliders/window.h4
2 files changed, 40 insertions, 5 deletions
diff --git a/examples/widgets/widgets/sliders/window.cpp b/examples/widgets/widgets/sliders/window.cpp
index 397c9b8b72..4a3520716d 100644
--- a/examples/widgets/widgets/sliders/window.cpp
+++ b/examples/widgets/widgets/sliders/window.cpp
@@ -3,10 +3,8 @@
#include "slidersgroup.h"
#include "window.h"
-
#include <QCheckBox>
#include <QComboBox>
-#include <QHBoxLayout>
#include <QLabel>
#include <QSpinBox>
#include <QStackedWidget>
@@ -34,9 +32,10 @@ Window::Window(QWidget *parent)
connect(valueSpinBox, &QSpinBox::valueChanged,
horizontalSliders, &SlidersGroup::setValue);
- QHBoxLayout *layout = new QHBoxLayout;
- layout->addWidget(controlsGroup);
- layout->addWidget(stackedWidget);
+ layout = new QGridLayout;
+ layout->addWidget(stackedWidget, 0, 1);
+ layout->addWidget(controlsGroup, 0, 0);
+
setLayout(layout);
minimumSpinBox->setValue(0);
@@ -110,5 +109,37 @@ void Window::createControls(const QString &title)
controlsLayout->addWidget(invertedKeyBindings, 1, 2);
controlsLayout->addWidget(orientationCombo, 3, 0, 1, 3);
controlsGroup->setLayout(controlsLayout);
+
}
//! [8]
+
+
+void Window::resizeEvent(QResizeEvent *e)
+{
+ if (width() == 0 || height() == 0)
+ return;
+
+ const double aspectRatio = double(width()) / double(height());
+
+ if ((aspectRatio < 1.0) && (oldAspectRatio > 1.0)) {
+ layout->removeWidget(controlsGroup);
+ layout->removeWidget(stackedWidget);
+
+ layout->addWidget(stackedWidget, 1, 0);
+ layout->addWidget(controlsGroup, 0, 0);
+
+ oldAspectRatio = aspectRatio;
+ }
+ else if ((aspectRatio > 1.0) && (oldAspectRatio < 1.0)) {
+ layout->removeWidget(controlsGroup);
+ layout->removeWidget(stackedWidget);
+
+ layout->addWidget(stackedWidget, 0, 1);
+ layout->addWidget(controlsGroup, 0, 0);
+
+ oldAspectRatio = aspectRatio;
+ }
+}
+
+
+
diff --git a/examples/widgets/widgets/sliders/window.h b/examples/widgets/widgets/sliders/window.h
index 8a98fcb2a1..fa627eabd3 100644
--- a/examples/widgets/widgets/sliders/window.h
+++ b/examples/widgets/widgets/sliders/window.h
@@ -5,6 +5,7 @@
#define WINDOW_H
#include <QWidget>
+#include <QGridLayout>
QT_BEGIN_NAMESPACE
class QCheckBox;
@@ -26,6 +27,7 @@ public:
private:
void createControls(const QString &title);
+ void resizeEvent(QResizeEvent *e);
SlidersGroup *horizontalSliders;
SlidersGroup *verticalSliders;
@@ -41,6 +43,8 @@ private:
QSpinBox *maximumSpinBox;
QSpinBox *valueSpinBox;
QComboBox *orientationCombo;
+ QGridLayout *layout;
+ double oldAspectRatio;
};
//! [0]