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 Change-Id: I00009cb6c8c250a8333ac3dfa635f70da4576d5e Reviewed-by: Richard Moe Gustavsen <richard.gustavsen@qt.io> Reviewed-by: Jani Korteniemi <jani.korteniemi@qt.io> (cherry picked from commit 1a6019438881b9aa54cfc8dbd3f8fc06ddc35d67) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
807fd5684a
commit
15f15fa8db
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -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]
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user