1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
|
'\" t
.TH QGridLayout 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*-
.\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the
.\" license file included in the distribution for a complete license
.\" statement.
.\"
.ad l
.nh
.SH NAME
QGridLayout \- Lays out widgets in a grid
.SH SYNOPSIS
\fC#include <qlayout.h>\fR
.PP
Inherits QLayout.
.PP
.SS "Public Members"
.in +1c
.ti -1c
.BI "\fBQGridLayout\fR ( QWidget * parent, int nRows = 1, int nCols = 1, int margin = 0, int space = -1, const char * name = 0 )"
.br
.ti -1c
.BI "\fBQGridLayout\fR ( int nRows = 1, int nCols = 1, int spacing = -1, const char * name = 0 )"
.br
.ti -1c
.BI "\fBQGridLayout\fR ( QLayout * parentLayout, int nRows = 1, int nCols = 1, int spacing = -1, const char * name = 0 )"
.br
.ti -1c
.BI "\fB~QGridLayout\fR ()"
.br
.ti -1c
.BI "virtual QSize \fBsizeHint\fR () const"
.br
.ti -1c
.BI "virtual QSize \fBminimumSize\fR () const"
.br
.ti -1c
.BI "virtual QSize \fBmaximumSize\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetRowStretch\fR ( int row, int stretch )"
.br
.ti -1c
.BI "virtual void \fBsetColStretch\fR ( int col, int stretch )"
.br
.ti -1c
.BI "int \fBrowStretch\fR ( int row ) const"
.br
.ti -1c
.BI "int \fBcolStretch\fR ( int col ) const"
.br
.ti -1c
.BI "void \fBsetRowSpacing\fR ( int row, int minSize )"
.br
.ti -1c
.BI "void \fBsetColSpacing\fR ( int col, int minSize )"
.br
.ti -1c
.BI "int \fBrowSpacing\fR ( int row ) const"
.br
.ti -1c
.BI "int \fBcolSpacing\fR ( int col ) const"
.br
.ti -1c
.BI "int \fBnumRows\fR () const"
.br
.ti -1c
.BI "int \fBnumCols\fR () const"
.br
.ti -1c
.BI "QRect \fBcellGeometry\fR ( int row, int col ) const"
.br
.ti -1c
.BI "virtual bool \fBhasHeightForWidth\fR () const"
.br
.ti -1c
.BI "virtual int \fBheightForWidth\fR ( int w ) const"
.br
.ti -1c
.BI "virtual QSizePolicy::ExpandData \fBexpanding\fR () const"
.br
.ti -1c
.BI "virtual void \fBinvalidate\fR ()"
.br
.ti -1c
.BI "virtual void \fBaddItem\fR ( QLayoutItem * item )"
.br
.ti -1c
.BI "void \fBaddItem\fR ( QLayoutItem * item, int row, int col )"
.br
.ti -1c
.BI "void \fBaddMultiCell\fR ( QLayoutItem * item, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )"
.br
.ti -1c
.BI "void \fBaddWidget\fR ( QWidget * w, int row, int col, int alignment = 0 )"
.br
.ti -1c
.BI "void \fBaddMultiCellWidget\fR ( QWidget * w, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )"
.br
.ti -1c
.BI "void \fBaddLayout\fR ( QLayout * layout, int row, int col )"
.br
.ti -1c
.BI "void \fBaddMultiCellLayout\fR ( QLayout * layout, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )"
.br
.ti -1c
.BI "void addRowSpacing ( int row, int minsize ) \fI(obsolete)\fR"
.br
.ti -1c
.BI "void addColSpacing ( int col, int minsize ) \fI(obsolete)\fR"
.br
.ti -1c
.BI "void \fBexpand\fR ( int nRows, int nCols )"
.br
.ti -1c
.BI "enum \fBCorner\fR { TopLeft, TopRight, BottomLeft, BottomRight }"
.br
.ti -1c
.BI "void \fBsetOrigin\fR ( Corner c )"
.br
.ti -1c
.BI "Corner \fBorigin\fR () const"
.br
.ti -1c
.BI "virtual void \fBsetGeometry\fR ( const QRect & r )"
.br
.in -1c
.SS "Protected Members"
.in +1c
.ti -1c
.BI "bool \fBfindWidget\fR ( QWidget * w, int * row, int * col )"
.br
.ti -1c
.BI "void \fBadd\fR ( QLayoutItem * item, int row, int col )"
.br
.in -1c
.SH DESCRIPTION
The QGridLayout class lays out widgets in a grid.
.PP
QGridLayout takes the space made available to it (by its parent layout or by the mainWidget()), divides it up into rows and columns, and puts each widget it manages into the correct cell.
.PP
Columns and rows behave identically; we will discuss columns, but there are equivalent functions for rows.
.PP
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.
.PP
Normally, each managed widget or layout is put into a cell of its own using addWidget(), addLayout() or by the auto-add facility. It is also possible for a widget to occupy multiple cells using addMultiCellWidget(). If you do this, QGridLayout will guess how to distribute the size over the columns/rows (based on the stretch factors).
.PP
To remove a widget from a layout, call remove(). Calling QWidget::hide() on a widget also effectively removes the widget from the layout until QWidget::show() is called.
.PP
This illustration shows a fragment of a dialog with a five-column, three-row grid (the grid is shown overlaid in magenta):
.PP
<center>
.ce 1
.B "[Image Omitted]"
.PP
</center>
.PP
Columns 0, 2 and 4 in this dialog fragment are made up of a QLabel, a QLineEdit, and a QListBox. Columns 1 and 3 are placeholders made with addColSpacing(). Row 0 consists of three QLabel objects, row 1 of three QLineEdit objects and row 2 of three QListBox objects. We used placeholder columns (1 and 3) to get the right amount of space between the columns.
.PP
Note that the columns and rows are not equally wide or tall. If you want two columns to have the same width, you must set their minimum widths and stretch factors to be the same yourself. You do this using addColSpacing() and setColStretch().
.PP
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().
.PP
Once you have added your layout you can start putting widgets and other layouts into the cells of your grid layout using addWidget(), addLayout() and addMultiCellWidget().
.PP
QGridLayout also includes two margin widths: the border and the spacing. The border is the width of the reserved space along each of the QGridLayout's four sides. The spacing is the width of the automatically allocated spacing between neighboring boxes.
.PP
Both the border and the spacing are parameters of the constructor and default to 0.
.PP
See also QGrid, Layout Overview, Widget Appearance and Style, and Layout Management.
.SS "Member Type Documentation"
.SH "QGridLayout::Corner"
This enum identifies which corner is the origin (0, 0) of the layout.
.TP
\fCQGridLayout::TopLeft\fR - the top-left corner
.TP
\fCQGridLayout::TopRight\fR - the top-right corner
.TP
\fCQGridLayout::BottomLeft\fR - the bottom-left corner
.TP
\fCQGridLayout::BottomRight\fR - the bottom-right corner
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QGridLayout::QGridLayout ( QWidget * parent, int nRows = 1, int nCols = 1, int margin = 0, int space = -1, const char * name = 0 )"
Constructs a new QGridLayout with \fInRows\fR rows, \fInCols\fR columns and parent widget, \fIparent\fR. \fIparent\fR may not be 0. The grid layout is called \fIname\fR.
.PP
\fImargin\fR is the number of pixels between the edge of the widget and its managed children. \fIspace\fR is the default number of pixels between cells. If \fIspace\fR is -1, the value of \fImargin\fR is used.
.SH "QGridLayout::QGridLayout ( int nRows = 1, int nCols = 1, int spacing = -1, const char * name = 0 )"
Constructs a new grid with \fInRows\fR rows and \fInCols\fR columns. If \fIspacing\fR is -1, this QGridLayout inherits its parent's spacing(); otherwise \fIspacing\fR is used. The grid layout is called \fIname\fR.
.PP
You must insert this grid into another layout. You can insert widgets and layouts into this layout at any time, but laying out will not be performed before this is inserted into another layout.
.SH "QGridLayout::QGridLayout ( QLayout * parentLayout, int nRows = 1, int nCols = 1, int spacing = -1, const char * name = 0 )"
Constructs a new grid that is placed inside \fIparentLayout\fR with \fInRows\fR rows and \fInCols\fR columns. If \fIspacing\fR is -1, this QGridLayout inherits its parent's spacing(); otherwise \fIspacing\fR is used. The grid layout is called \fIname\fR.
.PP
This grid is placed according to \fIparentLayout\fR's default placement rules.
.SH "QGridLayout::~QGridLayout ()"
Destroys the grid layout. Geometry management is terminated if this is a top-level grid.
.PP
The layout's widgets aren't destroyed.
.SH "void QGridLayout::add ( QLayoutItem * item, int row, int col )\fC [protected]\fR"
Adds \fIitem\fR at position \fIrow\fR, \fIcol\fR. The layout takes ownership of the \fIitem\fR.
.SH "void QGridLayout::addColSpacing ( int col, int minsize )"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Sets the minimum width of column \fIcol\fR to \fIminsize\fR pixels.
.PP
Use setColSpacing() instead.
.SH "void QGridLayout::addItem ( QLayoutItem * item, int row, int col )"
Adds \fIitem\fR at position \fIrow\fR, \fIcol\fR. The layout takes ownership of the \fIitem\fR.
.SH "void QGridLayout::addItem ( QLayoutItem * item )\fC [virtual]\fR"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
Adds \fIitem\fR to the next free position of this layout.
.PP
Reimplemented from QLayout.
.SH "void QGridLayout::addLayout ( QLayout * layout, int row, int col )"
Places the \fIlayout\fR at position (\fIrow\fR, \fIcol\fR) in the grid. The top-left position is (0, 0).
.PP
\fIlayout\fR becomes a child of the grid layout.
.PP
When a layout is constructed with another layout as its parent, you don't need to call addLayout(); the child layout is automatically added to the parent layout as it is constructed.
.PP
See also addMultiCellLayout().
.PP
Examples:
.)l listbox/listbox.cpp, progressbar/progressbar.cpp, t10/main.cpp, and t13/gamebrd.cpp.
.SH "void QGridLayout::addMultiCell ( QLayoutItem * item, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )"
Adds the \fIitem\fR to the cell grid, spanning multiple rows/columns.
.PP
The cell will span from \fIfromRow\fR, \fIfromCol\fR to \fItoRow\fR, \fItoCol\fR. Alignment is specified by \fIalignment\fR, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
.SH "void QGridLayout::addMultiCellLayout ( QLayout * layout, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )"
Adds the layout \fIlayout\fR to the cell grid, spanning multiple rows/columns. The cell will span from \fIfromRow\fR, \fIfromCol\fR to \fItoRow\fR, \fItoCol\fR.
.PP
Alignment is specified by \fIalignment\fR, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
.PP
A non-zero alignment indicates that the layout should not grow to fill the available space but should be sized according to sizeHint().
.PP
\fIlayout\fR becomes a child of the grid layout.
.PP
See also addLayout().
.SH "void QGridLayout::addMultiCellWidget ( QWidget * w, int fromRow, int toRow, int fromCol, int toCol, int alignment = 0 )"
Adds the widget \fIw\fR to the cell grid, spanning multiple rows/columns. The cell will span from \fIfromRow\fR, \fIfromCol\fR to \fItoRow\fR, \fItoCol\fR.
.PP
Alignment is specified by \fIalignment\fR, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
.PP
A non-zero alignment indicates that the widget should not grow to fill the available space but should be sized according to sizeHint().
.PP
See also addWidget().
.PP
Examples:
.)l cursor/cursor.cpp, layout/layout.cpp, and progressbar/progressbar.cpp.
.SH "void QGridLayout::addRowSpacing ( int row, int minsize )"
\fBThis function is obsolete.\fR It is provided to keep old source working. We strongly advise against using it in new code.
.PP
Sets the minimum height of row \fIrow\fR to \fIminsize\fR pixels.
.PP
Use setRowSpacing() instead.
.SH "void QGridLayout::addWidget ( QWidget * w, int row, int col, int alignment = 0 )"
Adds the widget \fIw\fR to the cell grid at \fIrow\fR, \fIcol\fR. The top-left position is (0, 0) by default.
.PP
Alignment is specified by \fIalignment\fR, which is a bitwise OR of Qt::AlignmentFlags values. The default alignment is 0, which means that the widget fills the entire cell.
.TP
You should not call this if you have enabled the auto-add facility of the layout.
.IP
.TP
From Qt 3.0, the \fIalignment\fR 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().
.PP
See also addMultiCellWidget().
.PP
Examples:
.)l addressbook/centralwidget.cpp, layout/layout.cpp, rot13/rot13.cpp, sql/overview/form1/main.cpp, sql/overview/form2/main.cpp, t14/gamebrd.cpp, and t8/main.cpp.
.SH "QRect QGridLayout::cellGeometry ( int row, int col ) const"
Returns the geometry of the cell with row \fIrow\fR and column \fIcol\fR in the grid. Returns an invalid rectangle if \fIrow\fR or \fIcol\fR is outside the grid.
.PP
\fBWarning:\fR 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.
.SH "int QGridLayout::colSpacing ( int col ) const"
Returns the column spacing for column \fIcol\fR.
.PP
See also setColSpacing().
.SH "int QGridLayout::colStretch ( int col ) const"
Returns the stretch factor for column \fIcol\fR.
.PP
See also setColStretch().
.SH "void QGridLayout::expand ( int nRows, int nCols )"
Expands this grid so that it will have \fInRows\fR rows and \fInCols\fR columns. Will not shrink the grid. You should not need to call this function because QGridLayout expands automatically as new items are inserted.
.SH "QSizePolicy::ExpandData QGridLayout::expanding () const\fC [virtual]\fR"
Returns whether this layout can make use of more space than sizeHint(). A value of Vertical or Horizontal means that it wants to grow in only one dimension, whereas \fCBothDirections\fR means that it wants to grow in both dimensions.
.PP
Reimplemented from QLayout.
.SH "bool QGridLayout::findWidget ( QWidget * w, int * row, int * col )\fC [protected]\fR"
Searches for widget \fIw\fR in this layout (not including child layouts). If \fIw\fR is found, it sets \fC<em>row</em>\fR and \fC<em>col</em>\fR to the row and column and returns TRUE; otherwise returns FALSE.
.PP
Note: if a widget spans multiple rows/columns, the top-left cell is returned.
.SH "bool QGridLayout::hasHeightForWidth () const\fC [virtual]\fR"
Returns TRUE if this layout's preferred height depends on its width; otherwise returns FALSE.
.PP
Reimplemented from QLayoutItem.
.SH "int QGridLayout::heightForWidth ( int w ) const\fC [virtual]\fR"
Returns the layout's preferred height when it is \fIw\fR pixels wide.
.PP
Reimplemented from QLayoutItem.
.SH "void QGridLayout::invalidate ()\fC [virtual]\fR"
Resets cached information.
.PP
Reimplemented from QLayout.
.SH "QSize QGridLayout::maximumSize () const\fC [virtual]\fR"
Returns the maximum size needed by this grid.
.PP
Reimplemented from QLayout.
.SH "QSize QGridLayout::minimumSize () const\fC [virtual]\fR"
Returns the minimum size needed by this grid.
.PP
Reimplemented from QLayout.
.SH "int QGridLayout::numCols () const"
Returns the number of columns in this grid.
.SH "int QGridLayout::numRows () const"
Returns the number of rows in this grid.
.SH "Corner QGridLayout::origin () const"
Returns the corner that's used for the grid's origin, i.e. for position (0, 0).
.SH "int QGridLayout::rowSpacing ( int row ) const"
Returns the row spacing for row \fIrow\fR.
.PP
See also setRowSpacing().
.SH "int QGridLayout::rowStretch ( int row ) const"
Returns the stretch factor for row \fIrow\fR.
.PP
See also setRowStretch().
.SH "void QGridLayout::setColSpacing ( int col, int minSize )"
Sets the minimum width of column \fIcol\fR to \fIminSize\fR pixels.
.PP
See also colSpacing() and setRowSpacing().
.SH "void QGridLayout::setColStretch ( int col, int stretch )\fC [virtual]\fR"
Sets the stretch factor of column \fIcol\fR to \fIstretch\fR. The first column is number 0.
.PP
The stretch factor is relative to the other columns in this grid. Columns with a higher stretch factor take more of the available space.
.PP
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.
.PP
See also colStretch(), addColSpacing(), and setRowStretch().
.PP
Examples:
.)l layout/layout.cpp, t14/gamebrd.cpp, and t8/main.cpp.
.SH "void QGridLayout::setGeometry ( const QRect & r )\fC [virtual]\fR"
Resizes managed widgets within the rectangle \fIr\fR.
.PP
Reimplemented from QLayout.
.SH "void QGridLayout::setOrigin ( Corner c )"
Sets the grid's origin corner, i.e. position (0, 0), to \fIc\fR.
.SH "void QGridLayout::setRowSpacing ( int row, int minSize )"
Sets the minimum height of row \fIrow\fR to \fIminSize\fR pixels.
.PP
See also rowSpacing() and setColSpacing().
.SH "void QGridLayout::setRowStretch ( int row, int stretch )\fC [virtual]\fR"
Sets the stretch factor of row \fIrow\fR to \fIstretch\fR. The first row is number 0.
.PP
The stretch factor is relative to the other rows in this grid. Rows with a higher stretch factor take more of the available space.
.PP
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.
.PP
See also rowStretch(), setRowSpacing(), and setColStretch().
.PP
Examples:
.)l addressbook/centralwidget.cpp and qutlook/centralwidget.cpp.
.SH "QSize QGridLayout::sizeHint () const\fC [virtual]\fR"
Returns the preferred size of this grid.
.PP
Reimplemented from QLayoutItem.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qgridlayout.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qgridlayout.3qt) and the Qt
version (3.3.8).
|