![]() |
| ||
Classes - Annotated - Tree - Functions - Home - Structure |
The QGridLayout class lays out widgets in a grid. More...
#include <qlayout.h>
Inherits QLayout.
The QGridLayout class lays out widgets in a grid.
QGridLayout takes the space it gets (from its parent layout or from the mainWidget()), divides it up into rows and columns, and puts each of the widgets it manages into the correct cell(s).
Columns and rows behave identically; we will discuss columns, but there are equivalent functions for rows.
Each column has a minimum width and a stretch factor. The minimum width is the greatest of that set using addColSpacing() and the minimum width of each widget in that column. The stretch factor is set using setColStretch() and determines how much of the available space the column will get over and above its necessary minimum.
Normally, each managed widget or layout is put into a cell of its own using addWidget(), addLayout(), or by the auto-add facility; but you can also put widget into multiple cells using addMultiCellWidget(). If you do that, QGridLayout will guess how to distribute the size over the columns/rows (based on the stretch factors). You can adjust the minimum width of each column/row using addColSpacing()/addRowSpacing().
This illustration shows a fragment of a dialog with a five-column, three-row grid (the grid is shown overlaid in magenta):
Columns 0, 2 and 4 in this dialog fragment are made up of a QLabel, a QLineEdit, and a QListBox. Columns 1 and 2 are placeholders made with setColSpacing(). Row 0 consists of three QLabel objects, row 1 of three QLineEdit objects and row 2 of three QListBox objects.
Because we did not want any space between the rows, we had to use placeholder columns to get the right amount of space between the columns.
Note that the columns and rows are not equally wide/tall: If you want two columns to be equally wide, you must set the columns' minimum widths and stretch factors to be the same yourself. You do this using addColSpacing() and setStretch().
If the QGridLayout is not the top-level layout (i.e., does not manage all of the widget's area and children), you must add it to its parent layout when you create it - but before you do anything with it. The normal way to add a layout is by calling parentLayout->addLayout().
Once you have done that you can start putting widgets and other layouts into the cells of your grid layout using addWidget(), addLayout(), and addMultiCellWidget().
QGridLayout also includes two margin widths: the border width and the inter-box width. The border width is the width of the reserved space along each of the QGridLayout's four sides. The intra-widget width is the width of the automatically allocated spacing between neighboring boxes.
The border width defaults to 0; the intra-widget width defaults to the same. Both are set using arguments to the constructor.
See also the Layout Overview documentation.
border is the number of pixels between the edge of the widget and the managed children. space is the default number of pixels between cells. If space is -1, the value of border is used.
name is the internal object name.
You have to insert this grid into another layout. You can insert widgets and layouts in this layout at any time, but layout will not be performed before it is inserted.
This grid is placed according to parentLayout's default placement rules.
Reimplemented from QLayout.
Examples: t10/main.cpp, t11/main.cpp, t12/main.cpp, t13/gamebrd.cpp and t14/gamebrd.cpp.
Alignment is specified by alignment, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
Alignment is specified by alignment, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
A non-zero alignment indicates that the layout should not grow to fill the available space but should be sized according to sizeHint().
Alignment is specified by alignment, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
A non-zero alignment indicates that the widget should not grow to fill the available space but should be sized according to sizeHint().
Examples: cursor/cursor.cpp, layout/layout.cpp and progressbar/progressbar.cpp.
Alignment is specified by alignment, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
Note 1: You should not call this if you have enabled the auto-add facility of the layout.
Note 2: The alignment parameter is interpreted more aggressively than in previous versions of Qt. A non-default alignment now indicates that the widget should not grow to fill the available space, but should be sized according to sizeHint().
Examples: addressbook/centralwidget.cpp, sql/overview/form1/main.cpp, t10/main.cpp, t14/gamebrd.cpp, t8/main.cpp and t9/main.cpp.
Warning: in the current version of Qt this function does not return valid results until setGeometry() has been called, i.e., after the mainWidget() is visible.
See also setColStretch().
Reimplemented from QLayout.
Warning: If a widget spans multiple rows/columns, the top-left cell is returned.
Reimplemented from QLayoutItem.
Reimplemented from QLayoutItem.
Reimplemented from QLayout.
Reimplemented from QLayout.
Reimplemented from QLayout.
See also setRowStretch().
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.
See also colStretch(), addColSpacing() and setRowStretch().
Examples: layout/layout.cpp, t10/main.cpp, t11/main.cpp, t14/gamebrd.cpp, t8/main.cpp and t9/main.cpp.
Reimplemented from QLayout.
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.
See also rowStretch(), addRowSpacing() and setColStretch().
Example: addressbook/centralwidget.cpp.
Reimplemented from QLayoutItem.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2001 Trolltech, all rights reserved.
Copyright © 2001 Trolltech | Trademarks | Qt version 3.0.0-beta1-beta1
|