×
Namespaces

Variants
Actions

Archived:How to use QGridLayout

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 (based on QWidget) is deprecated.

This (archived) example shows how to lay out widgets in a Grid using QGridLayout.

Article Metadata
Tested with
Devices(s): Emulator
Compatibility
Platform(s): S60 3rd Edition, S60 5th Edition
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QGridLayout
Created: james1980 (29 Dec 2008)
Last edited: hamishwillee (11 Oct 2012)

Like the form layout, this is also very easy to handle and widgets are arranged easily. You just have to arrange them like a matrix and give them a number like (0,1) or (1,1), which means the widget is displayed at row 0 and 1st column or in the 1st row and 1st column.

Contents

Preconditions

  • Download and Install the Qt SDK

Various Function For QGridLayout

  • To set the Vertical spacing between rows.
QGridLayout *gridLayout=new QGridLayout ();
gridLayout->setVerticalSpacing(50);


Grid spacing.JPG

  • To set vertical as well as horizontal spacing simultaneously.
gridLayout->Spacing(50);

 

Onlyspacing.JPG

  • To set minimum height of row setRowMinimumHeight(int row,int height) as well as to Sets the minimum width of column setColumnMinimumWidth(int column,int width).
gridLayout->setRowMinimumHeight(1,400);
gridLayout->setColumnMinimumWidth(1,200);

Setrowminheight.JPG

For more details in QGridLayout visit: http://doc.trolltech.com/3.3/qgridlayout.html

Code

#include <QApplication>
#include <QGridLayout>
#include <QLineEdit>
#include <QSpinBox>
#include <QWidget>
#include <QLabel>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QLineEdit *nameLineEdit = new QLineEdit;
QLineEdit *emailLineEdit = new QLineEdit;
QSpinBox *ageSpinBox = new QSpinBox;
QWidget *win = new QWidget;
QLabel *nameLabel = new QLabel(("&Name:"));
nameLabel->setBuddy(nameLineEdit);
QLabel *emailLabel = new QLabel(("&Email:"));
emailLabel->setBuddy(emailLineEdit);
QLabel *ageLabel = new QLabel(("&Age:"));
ageLabel->setBuddy(ageSpinBox);
QGridLayout *gridLayout = new QGridLayout;
gridLayout->addWidget(nameLabel, 0, 0);
gridLayout->addWidget(nameLineEdit, 0, 1);
gridLayout->addWidget(emailLabel, 1, 0);
gridLayout->addWidget(emailLineEdit, 1, 1);
gridLayout->addWidget(ageLabel, 2, 0);
gridLayout->addWidget(ageSpinBox, 2, 1);
win->setLayout(gridLayout);
win->show();
 
return app.exec();
}


Screen Shot

Gridlayout.jpg

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