source: trunk/doc/src/qsizepolicy.qdoc@ 342

Last change on this file since 342 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 16.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the documentation of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \class QSizePolicy
44 \brief The QSizePolicy class is a layout attribute describing horizontal
45 and vertical resizing policy.
46
47 \ingroup appearance
48 \ingroup geomanagement
49
50 The size policy of a widget is an expression of its willingness to
51 be resized in various ways, and affects how the widget is treated
52 by the \l{Layout Management}{layout engine}. Each widget returns a
53 QSizePolicy that describes the horizontal and vertical resizing
54 policy it prefers when being laid out. You can change this for
55 a specific widget by changing its QWidget::sizePolicy property.
56
57 QSizePolicy contains two independent QSizePolicy::Policy values
58 and two stretch factors; one describes the widgets's horizontal
59 size policy, and the other describes its vertical size policy. It
60 also contains a flag to indicate whether the height and width of
61 its preferred size are related.
62
63 The horizontal and vertical policies can be set in the
64 constructor, and altered using the setHorizontalPolicy() and
65 setVerticalPolicy() functions. The stretch factors can be set
66 using the setHorizontalStretch() and setVerticalStretch()
67 functions. The flag indicating whether the widget's
68 \l{QWidget::sizeHint()}{sizeHint()} is width-dependent (such as a
69 menu bar or a word-wrapping label) can be set using the
70 setHeightForWidth() function.
71
72 The current size policies and stretch factors be retrieved using
73 the horizontalPolicy(), verticalPolicy(), horizontalStretch() and
74 verticalStretch() functions. Alternatively, use the transpose()
75 function to swap the horizontal and vertical policies and
76 stretches. The hasHeightForWidth() function returns the current
77 status of the flag indicating the size hint dependencies.
78
79 Use the expandingDirections() function to determine whether the
80 associated widget can make use of more space than its
81 \l{QWidget::sizeHint()}{sizeHint()} function indicates, as well as
82 find out in which directions it can expand.
83
84 Finally, the QSizePolicy class provides operators comparing this
85 size policy to a given policy, as well as a QVariant operator
86 storing this QSizePolicy as a QVariant object.
87
88 \sa QSize, QWidget::sizeHint(), QWidget::sizePolicy,
89 QLayoutItem::sizeHint()
90*/
91
92/*!
93 \enum QSizePolicy::PolicyFlag
94
95 These flags are combined together to form the various \l{Policy}
96 values:
97
98 \value GrowFlag The widget can grow beyond its size hint if necessary.
99 \value ExpandFlag The widget should get as much space as possible.
100 \value ShrinkFlag The widget can shrink below its size hint if necessary.
101 \value IgnoreFlag The widget's size hint is ignored. The widget will get
102 as much space as possible.
103
104 \sa Policy
105*/
106
107/*!
108 \enum QSizePolicy::Policy
109
110 This enum describes the various per-dimension sizing types used
111 when constructing a QSizePolicy.
112
113 \value Fixed The QWidget::sizeHint() is the only acceptable
114 alternative, so the widget can never grow or shrink (e.g. the
115 vertical direction of a push button).
116
117 \value Minimum The sizeHint() is minimal, and sufficient. The
118 widget can be expanded, but there is no advantage to it being
119 larger (e.g. the horizontal direction of a push button).
120 It cannot be smaller than the size provided by sizeHint().
121
122 \value Maximum The sizeHint() is a maximum. The widget can be
123 shrunk any amount without detriment if other widgets need the
124 space (e.g. a separator line).
125 It cannot be larger than the size provided by sizeHint().
126
127 \value Preferred The sizeHint() is best, but the widget can be
128 shrunk and still be useful. The widget can be expanded, but there
129 is no advantage to it being larger than sizeHint() (the default
130 QWidget policy).
131
132 \value Expanding The sizeHint() is a sensible size, but the
133 widget can be shrunk and still be useful. The widget can make use
134 of extra space, so it should get as much space as possible (e.g.
135 the horizontal direction of a horizontal slider).
136
137 \value MinimumExpanding The sizeHint() is minimal, and sufficient.
138 The widget can make use of extra space, so it should get as much
139 space as possible (e.g. the horizontal direction of a horizontal
140 slider).
141
142 \value Ignored The sizeHint() is ignored. The widget will get as
143 much space as possible.
144
145 \sa PolicyFlag, setHorizontalPolicy(), setVerticalPolicy()
146*/
147
148/*!
149 \fn QSizePolicy::QSizePolicy()
150
151 Constructs a QSizePolicy object with \l Fixed as its horizontal
152 and vertical policies.
153
154 The policies can be altered using the setHorizontalPolicy() and
155 setVerticalPolicy() functions. Use the setHeightForWidth()
156 function if the preferred height of the widget is dependent on the
157 width of the widget (for example, a QLabel with line wrapping).
158
159 \sa setHorizontalStretch(), setVerticalStretch()
160*/
161
162/*!
163 \fn QSizePolicy::QSizePolicy(Policy horizontal, Policy vertical)
164
165 Constructs a QSizePolicy object with the given \a horizontal and
166 \a vertical policies, and DefaultType as the control type.
167
168 Use setHeightForWidth() if the preferred height of the widget is
169 dependent on the width of the widget (for example, a QLabel with
170 line wrapping).
171
172 \sa setHorizontalStretch(), setVerticalStretch()
173*/
174
175/*!
176 \fn QSizePolicy::QSizePolicy(Policy horizontal, Policy vertical, ControlType type)
177 \since 4.3
178
179 Constructs a QSizePolicy object with the given \a horizontal and
180 \a vertical policies, and the specified control \a type.
181
182 Use setHeightForWidth() if the preferred height of the widget is
183 dependent on the width of the widget (for example, a QLabel with
184 line wrapping).
185
186 \sa setHorizontalStretch(), setVerticalStretch(), controlType()
187*/
188
189/*!
190 \fn QSizePolicy::Policy QSizePolicy::horizontalPolicy() const
191
192 Returns the horizontal component of the size policy.
193
194 \sa setHorizontalPolicy(), verticalPolicy(), horizontalStretch()
195*/
196
197/*!
198 \fn QSizePolicy::Policy QSizePolicy::verticalPolicy() const
199
200 Returns the vertical component of the size policy.
201
202 \sa setVerticalPolicy(), horizontalPolicy(), verticalStretch()
203*/
204
205/*!
206 \fn void QSizePolicy::setHorizontalPolicy(Policy policy)
207
208 Sets the horizontal component to the given \a policy.
209
210 \sa horizontalPolicy(), setVerticalPolicy(), setHorizontalStretch()
211*/
212
213/*!
214 \fn void QSizePolicy::setVerticalPolicy(Policy policy)
215
216 Sets the vertical component to the given \a policy.
217
218 \sa verticalPolicy(), setHorizontalPolicy(), setVerticalStretch()
219*/
220
221/*!
222 \fn Qt::Orientations QSizePolicy::expandingDirections() const
223
224 Returns whether a widget can make use of more space than the
225 QWidget::sizeHint() function indicates.
226
227 A value of Qt::Horizontal or Qt::Vertical means that the widget
228 can grow horizontally or vertically (i.e., the horizontal or
229 vertical policy is \l Expanding or \l MinimumExpanding), whereas
230 Qt::Horizontal | Qt::Vertical means that it can grow in both
231 dimensions.
232
233 \sa horizontalPolicy(), verticalPolicy()
234*/
235
236/*!
237 \fn ControlType QSizePolicy::controlType() const
238 \since 4.3
239
240 Returns the control type associated with the widget for which
241 this size policy applies.
242*/
243
244/*!
245 \fn void QSizePolicy::setControlType(ControlType type)
246 \since 4.3
247
248 Sets the control type associated with the widget for which this
249 size policy applies to \a type.
250
251 The control type specifies the type of the widget for which this
252 size policy applies. It is used by some styles, notably
253 QMacStyle, to insert proper spacing between widgets. For example,
254 the Mac OS X Aqua guidelines specify that push buttons should be
255 separated by 12 pixels, whereas vertically stacked radio buttons
256 only require 6 pixels.
257
258 \sa QStyle::layoutSpacing()
259*/
260
261/*!
262 \fn void QSizePolicy::setHeightForWidth(bool dependent)
263
264 Sets the flag determining whether the widget's preferred height
265 depends on its width, to \a dependent.
266
267 \sa hasHeightForWidth()
268*/
269
270/*!
271 \fn bool QSizePolicy::hasHeightForWidth() const
272
273 Returns true if the widget's preferred height depends on its
274 width; otherwise returns false.
275
276 \sa setHeightForWidth()
277*/
278
279/*!
280 \fn bool QSizePolicy::operator==(const QSizePolicy &other) const
281
282 Returns true if this policy is equal to \a other; otherwise
283 returns false.
284
285 \sa operator!=()
286*/
287
288/*!
289 \fn bool QSizePolicy::operator!=(const QSizePolicy &other) const
290
291 Returns true if this policy is different from \a other; otherwise
292 returns false.
293
294 \sa operator==()
295*/
296
297/*!
298 \fn int QSizePolicy::horizontalStretch() const
299
300 Returns the horizontal stretch factor of the size policy.
301
302 \sa setHorizontalStretch(), verticalStretch(), horizontalPolicy()
303*/
304
305/*!
306 \fn int QSizePolicy::verticalStretch() const
307
308 Returns the vertical stretch factor of the size policy.
309
310 \sa setVerticalStretch(), horizontalStretch(), verticalPolicy()
311*/
312
313/*!
314 \fn void QSizePolicy::setHorizontalStretch(uchar stretchFactor)
315
316 Sets the horizontal stretch factor of the size policy to the given \a
317 stretchFactor.
318
319 \sa horizontalStretch(), setVerticalStretch(), setHorizontalPolicy()
320*/
321
322/*!
323 \fn void QSizePolicy::setVerticalStretch(uchar stretchFactor)
324
325 Sets the vertical stretch factor of the size policy to the given
326 \a stretchFactor.
327
328 \sa verticalStretch(), setHorizontalStretch(), setVerticalPolicy()
329*/
330
331/*!
332 \fn void QSizePolicy::transpose()
333
334 Swaps the horizontal and vertical policies and stretches.
335*/
336
337/*!
338 \enum QSizePolicy::ControlType
339 \since 4.3
340
341 This enum specifies the different types of widgets in terms of
342 layout interaction:
343
344 \value DefaultType The default type, when none is specified.
345 \value ButtonBox A QDialogButtonBox instance.
346 \value CheckBox A QCheckBox instance.
347 \value ComboBox A QComboBox instance.
348 \value Frame A QFrame instance.
349 \value GroupBox A QGroupBox instance.
350 \value Label A QLabel instance.
351 \value Line A QFrame instance with QFrame::HLine or QFrame::VLine.
352 \value LineEdit A QLineEdit instance.
353 \value PushButton A QPushButton instance.
354 \value RadioButton A QRadioButton instance.
355 \value Slider A QAbstractSlider instance.
356 \value SpinBox A QAbstractSpinBox instance.
357 \value TabWidget A QTabWidget instance.
358 \value ToolButton A QToolButton instance.
359
360 \sa setControlType(), controlType()
361*/
362
363#ifdef QT3_SUPPORT
364/*!
365 \typedef QSizePolicy::SizeType
366 \compat
367
368 Use the QSizePolicy::Policy enum instead.
369*/
370
371/*!
372 \enum QSizePolicy::ExpandData
373 \compat
374
375 Use the Qt::Orientations enum instead.
376
377 \value NoDirection Use 0 instead.
378 \value Horizontally Use Qt::Horizontal instead.
379 \value Vertically Use Qt::Vertical instead.
380 \value BothDirections Use Qt::Horizontal | Qt::Vertical instead.
381*/
382
383/*!
384 \fn bool QSizePolicy::mayShrinkHorizontally() const
385
386 Use the horizontalPolicy() function combined with the
387 QSizePolicy::PolicyFlag enum instead.
388
389 \oldcode
390 bool policy = mayShrinkHorizontally();
391 \newcode
392 bool policy = horizontalPolicy() & QSizePolicy::ShrinkFlag;
393 \endcode
394*/
395
396/*!
397 \fn bool QSizePolicy::mayShrinkVertically() const
398
399 Use the verticalPolicy() function combined with the
400 QSizePolicy::PolicyFlag enum instead.
401
402 \oldcode
403 bool policy = mayShrinkVertically();
404 \newcode
405 bool policy = verticalPolicy() & QSizePolicy::ShrinkFlag;
406 \endcode
407*/
408
409/*!
410 \fn bool QSizePolicy::mayGrowHorizontally() const
411
412 Use the horizontalPolicy() function combined with the
413 QSizePolicy::PolicyFlag enum instead.
414
415 \oldcode
416 bool policy = mayGrowHorizontally();
417 \newcode
418 bool policy = horizontalPolicy() & QSizePolicy::GrowFlag;
419 \endcode
420*/
421
422/*!
423 \fn bool QSizePolicy::mayGrowVertically() const
424
425 Use the verticalPolicy() function combined with the
426 QSizePolicy::PolicyFlag enum instead.
427
428 \oldcode
429 bool policy = mayGrowVertically();
430 \newcode
431 bool policy = verticalPolicy() & QSizePolicy::GrowFlag;
432 \endcode
433*/
434
435/*!
436 \fn Qt::QSizePolicy::Orientations QSizePolicy::expanding() const
437
438 Use expandingDirections() instead.
439*/
440
441/*!
442 \fn QSizePolicy::QSizePolicy(Policy horizontal, Policy vertical, bool dependent)
443
444 Use the QSizePolicy() constructor and the setHeightForWidth()
445 function instead.
446
447 \oldcode
448 QSizePolicy *policy = new QSizePolicy(horizontal, vertical, dependent);
449 \newcode
450 QSizePolicy *policy = new QSizePolicy(horizontal, vertical);
451 policy->setHeightForWidth(dependent);
452 \endcode
453*/
454
455/*!
456 \fn QSizePolicy::QSizePolicy(Policy horizontal, Policy vertical, uchar horizontalStretch,
457 uchar verticalStretch, bool dependent)
458
459 Use the QSizePolicy() constructor and call the
460 setHorizontalStretch(), setVerticalStretch(), and
461 setHeightForWidth() functions instead.
462
463 \oldcode
464 QSizePolicy *policy = new QSizePolicy(horizontal, vertical,
465 horizontalStretch, verticalStretch,
466 dependent);
467 \newcode
468 QSizePolicy *policy = new QSizePolicy(horizontal, vertical);
469 policy->setHorizontalStretch(horizontalStretch);
470 policy->setVerticalStretch(verticalStretch);
471 policy->setHeightForWidth(dependent);
472 \endcode
473*/
474
475/*!
476 \fn QSizePolicy::Policy QSizePolicy::horData() const
477
478 Use horizontalPolicy() instead.
479*/
480
481/*!
482 \fn QSizePolicy::Policy QSizePolicy::verData() const
483
484 Use verticalPolicy() instead.
485*/
486
487/*!
488 \fn void QSizePolicy::setHorData(Policy policy)
489
490 Use setHorizontalPolicy() instead.
491*/
492
493/*!
494 \fn void QSizePolicy::setVerData(Policy policy)
495
496 Use setVerticalPolicy() instead.
497*/
498
499/*!
500 \fn uint QSizePolicy::horStretch() const
501
502 Use horizontalStretch() instead.
503*/
504
505/*!
506 \fn uint QSizePolicy::verStretch() const
507
508 Use verticalStretch() instead.
509*/
510
511/*!
512 \fn void QSizePolicy::setHorStretch(uchar stretch)
513
514 Use setHorizontalStretch() instead.
515*/
516
517/*!
518 \fn void QSizePolicy::setVerStretch(uchar stretch)
519
520 Use setVerticalStretch() instead.
521*/
522#endif
Note: See TracBrowser for help on using the repository browser.