Archived:Overriding the minimum size constraint of QLayout
Qt Quick should be used for all UI development on mobile devices. The approach described in this article (using C++ for the Qt app UI) is deprecated.
Article Metadata
Tested with
Compatibility
Maemo
Article
Contents |
Overview
Qt layouts default have minimum size constraint set for the containing QWidgets which results layout to have a minimum size. If the UI control containing this layout is resized smaller than this limit, the layout just wont get smaller. In mobile resolutions this often means that the corresponding UI control won't scale small enough and the control will be partially drawn outside of the screen.
By overriding the minimum size constraint we can force the layout to scale the containing widgets as small as needed.
Note: The containing widgets might be scaled smaller than they were meant to be scaled. This can result as degraded look and feel in the used widgets.
Preconditions
- Install Nokia Qt SDK see [1]
Overriding the minimum size restraint
minimumsize.pro
TEMPLATE = app
SOURCES += main.cpp
main.cpp
#include <QApplication>
#include <QWidget>
#include <QPushButton>
#include <QVBoxLayout>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget widget;
QLayout *layout = new QVBoxLayout;
#if defined(Q_OS_SYMBIAN) || defined(Q_WS_MAEMO_5)
layout->setSizeConstraint(QLayout::SetNoConstraint);
#endif
for(int i=0; i<10; i++) {
QPushButton *button = new QPushButton(QString("%1").arg(i+1));
layout->addWidget(button);
}
widget.setLayout(layout);
#ifdef Q_OS_SYMBIAN
widget.showMaximized();
#else
widget.show();
#endif
return app.exec();
}
Postconditions
Code example demonstrated of overriding the minimum size constraint of the given layout to force the widgets smaller than their minimum size.


(no comments yet)