QGridLayout Class Reference


The QGridLayout class specifies child widget geometry. More...

#include <qlayout.h>

Inherits QLayout.

List of all member functions.

Public Members

Protected Members


Detailed Description

The QGridLayout class specifies child widget geometry.

Contents are arranged in a grid. If you need a more flexible layout, see the QHBoxLayout and QVBoxLayout classes.

To avoid squashed widgets, each column and each row of the grid should have a a minimum size or a nonzero stretch factor. Stretch factors are set with setRowStretch() and setColStretch(). Minimum sizes are set by addColSpacing(), addRowSpacing() and by the minimum sizes of the widgets added.

Note that a widget which spans several rows or columns does not influence the minimum size of any of the rows/columns it spans.

Warning: The current version does not support deletion of child widgets. If you need to remove widgets that are under geometry management, you have to delete the layout manager first.

Examples: pref/pref.cpp layout/layout.cpp widgets/widgets.cpp


Member Function Documentation

QGridLayout::QGridLayout ( QWidget * parent, int nRows, int nCols, int border=0, int autoBorder = -1, const char * name=0 )

Constructs a new QGridLayout with nRows rows, nCols columns and main widget parent. parent may not be 0.

border is the number of pixels between the edge of the widget and the managed children. autoBorder is the default number of pixels between cells. If autoBorder is -1 the value of border is used.

name is the internal object name.

QGridLayout::QGridLayout ( int nRows, int nCols, int autoBorder = -1, const char * name=0 )

Constructs a new grid with nRows rows and nCols columns, If autoBorder is -1, this QGridLayout will inherits its parent's defaultBorder(), otherwise autoBorder is used.

You have to insert this grid into another layout before using it.

QGridLayout::~QGridLayout ()

Deletes this grid. Geometry management is terminated if this is a top-level grid.

void QGridLayout::addColSpacing ( int col, int minsize )

Sets the minimum height of col to minsize pixels.

void QGridLayout::addLayout ( QLayout * layout, int row, int col )

Places another layout at position (row, col) in the grid. The top left position is (0,0).

Examples: widgets/widgets.cpp

void QGridLayout::addMultiCellWidget ( QWidget * w, int fromRow, int toRow, int fromCol, int toCol, int align = 0 )

Adds the widget w to the cell grid, spanning multiple rows/columns.

Note that multicell widgets do not influence the minimum or maximum size of columns/rows they span. Use addColSpacing() or addRowSpacing() to set minimum sizes explicitly.

Alignment is specified by align which takes the same arguments as QLabel::setAlignment(), alignment has no effect unless you have set QWidget::maximumSize().

Examples: layout/layout.cpp widgets/widgets.cpp

void QGridLayout::addRowSpacing ( int row, int minsize )

Sets the minimum width of row to minsize pixels.

void QGridLayout::addWidget ( QWidget * w, int row, int col, int align = 0 )

Adds the widget w to the cell grid at row, col. The top left position is (0,0)

Alignment is specified by align which takes the same arguments as QLabel::setAlignment(). Note that widgets take all the space they can get; alignment has no effect unless you have set QWidget::maximumSize().

Examples: pref/pref.cpp layout/layout.cpp widgets/widgets.cpp

void QGridLayout::initGM () [virtual protected]

Initializes this grid.

Reimplemented from QLayout.

QChain * QGridLayout::mainHorizontalChain () [virtual protected]

This function returns the main horizontal chain.

Reimplemented from QLayout.

QChain * QGridLayout::mainVerticalChain () [virtual protected]

This function returns the main vertical chain.

Reimplemented from QLayout.

void QGridLayout::setColStretch ( int col, int stretch )

Sets the stretch factor of column col to stretch. The first column is number 0.

The stretch factor is relative to the other columns in this grid. Columns with higher stretch factor take more of the available space.

The default stretch factor is 0. If the stretch factor is 0 and no other column in this table can grow at all, the column may still grow.

Examples: pref/pref.cpp layout/layout.cpp widgets/widgets.cpp

void QGridLayout::setRowStretch ( int row, int stretch )

Sets the stretch factor of row row to stretch. The first row is number 0.

The stretch factor is relative to the other rows in this grid. Rows with higher stretch factor take more of the available space.

The default stretch factor is 0. If the stretch factor is 0 and no other row in this table can grow at all, the row may still grow.

Examples: widgets/widgets.cpp


This file is part of the Qt toolkit, copyright © 1995-97 Troll Tech, all rights reserved.

It was generated from the following files:


Generated at 19:08, 1997/10/09 for Qt version 1.31 by the webmaster at Troll Tech