×
Namespaces

Variants
Actions

Archived:Overriding the minimum size constraint of QLayout

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

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
Devices(s): N97, N900
Compatibility
Platform(s): Symbian
Maemo
Symbian
Article
Keywords: QLayout, minimum size constraint
Created: kratsan (07 Oct 2010)
Last edited: hamishwillee (11 Oct 2012)

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.

See also

This page was last modified on 11 October 2012, at 04:14.
74 page views in the last 30 days.
×