QSizePolicy(3qt)

πŸ“¦ version 3.3.8b, in fedora 43, fedora 44

πŸ’… QSizePolicy β€” the 3qt manual page, bestie edition ✨

okay so. you opened the QSizePolicy(3qt) man page and you're like "what is this" β€” don't worry, i got you. this is genuinely one of the most important little classes in Qt's layout world and honestly? it ate. let's go 🫢


🌸 NAME 🌸

QSizePolicy β€” the layout attribute that describes your horizontal and vertical resizing policy. it's the vibe check your widget gets before it's allowed to stretch. πŸ’–


✨ SYNOPSIS ✨

#include <qsizepolicy.h>

πŸ‘‘ Public Members

enum SizeType { Fixed = 0, Minimum = MayGrow, Maximum = MayShrink,
    Preferred = MayGrow | MayShrink, MinimumExpanding = MayGrow |
    ExpMask, Expanding = MayGrow | MayShrink | ExpMask, Ignored =
    ExpMask }
enum ExpandData { NoDirection = 0, Horizontally = 1, Vertically = 2,
    Horizontal = Horizontally, Vertical = Vertically, BothDirections =
    Horizontally | Vertically }
QSizePolicy ()
QSizePolicy ( SizeType hor, SizeType ver, bool hfw = FALSE )
QSizePolicy ( SizeType hor, SizeType ver, uchar horStretch, uchar
    verStretch, bool hfw = FALSE )
SizeType horData () const
SizeType verData () const
bool mayShrinkHorizontally () const
bool mayShrinkVertically () const
bool mayGrowHorizontally () const
bool mayGrowVertically () const
ExpandData expanding () const
void setHorData ( SizeType d )
void setVerData ( SizeType d )
void setHeightForWidth ( bool b )
bool hasHeightForWidth () const
bool operator== ( const QSizePolicy & s ) const
bool operator!= ( const QSizePolicy & s ) const
uint horStretch () const
uint verStretch () const
void setHorStretch ( uchar sf )
void setVerStretch ( uchar sf )
void transpose ()

πŸ¦‹ DESCRIPTION πŸ¦‹

so the QSizePolicy class is literally the layout attribute describing horizontal and vertical resizing policy. that's the whole personality. πŸ’…

think of a widget's size policy as an expression of its willingness to be resized in various ways. it's not a demand, it's a preference. it's giving "i could go bigger, but like, only if you want."

widgets that reimplement QWidget::sizePolicy() return a QSizePolicy that describes the horizontal and vertical resizing policy they prefer when being laid out. and here's the tea: only one of the constructors is of interest in most applications. so don't stress about the rest of them, bestie. 😭

QSizePolicy contains two independent SizeType objects; one describes the widget's horizontal size policy, and the other describes its vertical size policy. it also contains a flag to indicate whether the height and width of its preferred size are related. yes, related. they're in a situationship. πŸ™ˆ

the horizontal and vertical SizeTypes are set in the usual constructor and can be queried using a variety of functions.

the hasHeightForWidth() flag indicates whether the widget's sizeHint() is width-dependent (such as a word-wrapping label) or not.

see also QSizePolicy::SizeType, Widget Appearance and Style, and Layout Management. 🌈

πŸŽ€ Member Type Documentation

QSizePolicy::ExpandData

this enum type describes in which directions a widget can make use of extra space. there are four possible values:

  • QSizePolicy::NoDirection β€” the widget cannot make use of extra space in any direction. it's an independent icon, it needs nothing. πŸ’€
  • QSizePolicy::Horizontally β€” the widget can usefully be wider than the sizeHint().
  • QSizePolicy::Vertically β€” the widget can usefully be taller than the sizeHint().
  • QSizePolicy::BothDirections β€” the widget can usefully be both wider and taller than the sizeHint(). main character energy fr fr. πŸ‘‘

QSizePolicy::SizeType

the per-dimension sizing types used when constructing a QSizePolicy are:

  • QSizePolicy::Fixed β€” The QWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).
  • QSizePolicy::Minimum β€” The sizeHint() is minimal, and sufficient. The widget can be expanded, but there is no advantage to it being larger (e.g. the horizontal direction of a push button). It cannot be smaller than the size provided by sizeHint().
  • QSizePolicy::Maximum β€” The sizeHint() is a maximum. The widget can be shrunk any amount without detriment if other widgets need the space (e.g. a separator line). It cannot be larger than the size provided by sizeHint().
  • QSizePolicy::Preferred β€” The sizeHint() is best, but the widget can be shrunk and still be useful. The widget can be expanded, but there is no advantage to it being larger than sizeHint() (the default QWidget policy). this one is the default, so it's kind of the popular girl of size policies. ⭐
  • QSizePolicy::Expanding β€” The sizeHint() is a sensible size, but the widget can be shrunk and still be useful. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a slider).
  • QSizePolicy::MinimumExpanding β€” The sizeHint() is minimal, and sufficient. The widget can make use of extra space, so it should get as much space as possible (e.g. the horizontal direction of a slider).
  • QSizePolicy::Ignored β€” the sizeHint() is ignored. The widget will get as much space as possible. it said "sizeHint? never heard of her." πŸ”₯

🧚 MEMBER FUNCTION DOCUMENTATION 🧚

QSizePolicy::QSizePolicy ()

Constructs a minimally initialized QSizePolicy. it's baby. it's fresh. it's barely anything yet. 🌱

QSizePolicy::QSizePolicy ( SizeType hor, SizeType ver, bool hfw = FALSE )

This is the constructor normally used to return a value in the overridden QWidget::sizePolicy() function of a QWidget subclass. ✨

It constructs a QSizePolicy with independent horizontal and vertical sizing types, hor and ver respectively. These sizing types affect how the widget is treated by the layout engine.

If hfw is TRUE, the preferred height of the widget is dependent on the width of the widget (for example, a QLabel with line wrapping).

See also horData(), verData(), and hasHeightForWidth().

QSizePolicy::QSizePolicy ( SizeType hor, SizeType ver, uchar horStretch, uchar verStretch, bool hfw = FALSE )

Constructs a QSizePolicy with independent horizontal and vertical sizing types hor and ver, and stretch factors horStretch and verStretch.

If hfw is TRUE, the preferred height of the widget is dependent on the width of the widget.

See also horStretch() and verStretch().

ExpandData QSizePolicy::expanding () const

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 BothDirections means that it wants to grow in both dimensions.

See also mayShrinkHorizontally(), mayGrowHorizontally(), mayShrinkVertically(), and mayGrowVertically().

bool QSizePolicy::hasHeightForWidth () const

Returns TRUE if the widget's preferred height depends on its width; otherwise returns FALSE.

See also setHeightForWidth().

SizeType QSizePolicy::horData () const

Returns the horizontal component of the size policy.

See also setHorData(), verData(), and horStretch().

uint QSizePolicy::horStretch () const

Returns the horizontal stretch factor of the size policy.

See also setHorStretch() and verStretch().

bool QSizePolicy::mayGrowHorizontally () const

Returns TRUE if the widget can sensibly be wider than its sizeHint(); otherwise returns FALSE.

See also mayGrowVertically() and mayShrinkHorizontally().

bool QSizePolicy::mayGrowVertically () const

Returns TRUE if the widget can sensibly be taller than its sizeHint(); otherwise returns FALSE.

See also mayGrowHorizontally() and mayShrinkVertically().

bool QSizePolicy::mayShrinkHorizontally () const

Returns TRUE if the widget can sensibly be narrower than its sizeHint(); otherwise returns FALSE.

See also mayShrinkVertically() and mayGrowHorizontally().

bool QSizePolicy::mayShrinkVertically () const

Returns TRUE if the widget can sensibly be shorter than its sizeHint(); otherwise returns FALSE.

See also mayShrinkHorizontally() and mayGrowVertically().

bool QSizePolicy::operator!= ( const QSizePolicy & s ) const

Returns TRUE if this policy is different from s; otherwise returns FALSE.

See also operator==().

bool QSizePolicy::operator== ( const QSizePolicy & s ) const

Returns TRUE if this policy is equal to s; otherwise returns FALSE.

See also operator!=().

void QSizePolicy::setHeightForWidth ( bool b )

Sets the hasHeightForWidth() flag to b.

See also hasHeightForWidth().

void QSizePolicy::setHorData ( SizeType d )

Sets the horizontal component of the size policy to size type d.

See also horData() and setVerData().

void QSizePolicy::setHorStretch ( uchar sf )

Sets the horizontal stretch factor of the size policy to sf.

See also horStretch() and setVerStretch().

void QSizePolicy::setVerData ( SizeType d )

Sets the vertical component of the size policy to size type d.

See also verData() and setHorData().

void QSizePolicy::setVerStretch ( uchar sf )

Sets the vertical stretch factor of the size policy to sf.

See also verStretch() and setHorStretch().

void QSizePolicy::transpose ()

Swaps the horizontal and vertical policies and stretches. πŸ”„ glow-up via identity crisis, we love to see it.

SizeType QSizePolicy::verData () const

Returns the vertical component of the size policy.

See also setVerData(), horData(), and verStretch().

uint QSizePolicy::verStretch () const

Returns the vertical stretch factor of the size policy.

See also setVerStretch() and horStretch().


πŸ” SEE ALSO πŸ”


Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.


🌟 AUTHOR 🌟

Generated automatically from the source code. (not me though. i'm just the messenger. πŸ’…)


πŸ’€ BUGS πŸ’€

If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports help us to help you. Thank you. 🫢

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.

If you find errors in this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qsizepolicy.3qt) and the Qt version (3.3.8). πŸ‘‘


ngl bestie, if you made it this far you officially understand QSizePolicy better than half the people shipping widgets rn. iconic. 🌈

and that's the whole page! this beauty came to you courtesy of Trolltech AS, dated 2 February 2007 β€” aka QSizePolicy(3qt), still serving looks almost two decades later. periodt. πŸ’–πŸŽ€πŸ¦‹

πŸ“¦ where this page comes from