Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QSizePolicy Class

TheQSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.More...

Header:#include <QSizePolicy>

Public Types

enumControlType { DefaultType, ButtonBox, CheckBox, ComboBox, ..., ToolButton }
flagsControlTypes
enumPolicy { Fixed, Minimum, Maximum, Preferred, ..., Ignored }
enumPolicyFlag { GrowFlag, ExpandFlag, ShrinkFlag, IgnoreFlag }

Public Functions

QSizePolicy()
QSizePolicy(Policy horizontal, Policy vertical)
QSizePolicy(Policy horizontal, Policy vertical, ControlType type)
ControlTypecontrolType() const
Qt::OrientationsexpandingDirections() const
boolhasHeightForWidth() const
boolhasWidthForHeight() const
PolicyhorizontalPolicy() const
inthorizontalStretch() const
voidsetControlType(ControlType type)
voidsetHeightForWidth(bool dependent)
voidsetHorizontalPolicy(Policy policy)
voidsetHorizontalStretch(uchar stretchFactor)
voidsetVerticalPolicy(Policy policy)
voidsetVerticalStretch(uchar stretchFactor)
voidsetWidthForHeight(bool dependent)
voidtranspose()
PolicyverticalPolicy() const
intverticalStretch() const
operator QVariant() const
booloperator!=(const QSizePolicy & other) const
booloperator==(const QSizePolicy & other) const

Related Non-Members

QDataStream &operator<<(QDataStream & stream, const QSizePolicy & policy)
QDataStream &operator>>(QDataStream & stream, QSizePolicy & policy)

Detailed Description

TheQSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.

The size policy of a widget is an expression of its willingness to be resized in various ways, and affects how the widget is treated by thelayout engine. Each widget returns aQSizePolicy that describes the horizontal and vertical resizing policy it prefers when being laid out. You can change this for a specific widget by changing itsQWidget::sizePolicy property.

QSizePolicy contains two independentQSizePolicy::Policy values and two stretch factors; one describes the widgets'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.

The horizontal and vertical policies can be set in the constructor, and altered using thesetHorizontalPolicy() andsetVerticalPolicy() functions. The stretch factors can be set using thesetHorizontalStretch() andsetVerticalStretch() functions. The flag indicating whether the widget'ssizeHint() is width-dependent (such as a menu bar or a word-wrapping label) can be set using thesetHeightForWidth() function.

The current size policies and stretch factors be retrieved using thehorizontalPolicy(),verticalPolicy(),horizontalStretch() andverticalStretch() functions. Alternatively, use thetranspose() function to swap the horizontal and vertical policies and stretches. ThehasHeightForWidth() function returns the current status of the flag indicating the size hint dependencies.

Use theexpandingDirections() function to determine whether the associated widget can make use of more space than itssizeHint() function indicates, as well as find out in which directions it can expand.

Finally, theQSizePolicy class provides operators comparing this size policy to a given policy, as well as aQVariant operator storing thisQSizePolicy as aQVariant object.

See alsoQSize,QWidget::sizeHint(),QWidget::sizePolicy, andQLayoutItem::sizeHint().

Member Type Documentation

enum QSizePolicy::ControlType
flags QSizePolicy::ControlTypes

This enum specifies the different types of widgets in terms of layout interaction:

ConstantValueDescription
QSizePolicy::DefaultType0x00000001The default type, when none is specified.
QSizePolicy::ButtonBox0x00000002AQDialogButtonBox instance.
QSizePolicy::CheckBox0x00000004AQCheckBox instance.
QSizePolicy::ComboBox0x00000008AQComboBox instance.
QSizePolicy::Frame0x00000010AQFrame instance.
QSizePolicy::GroupBox0x00000020AQGroupBox instance.
QSizePolicy::Label0x00000040AQLabel instance.
QSizePolicy::Line0x00000080AQFrame instance withQFrame::HLine orQFrame::VLine.
QSizePolicy::LineEdit0x00000100AQLineEdit instance.
QSizePolicy::PushButton0x00000200AQPushButton instance.
QSizePolicy::RadioButton0x00000400AQRadioButton instance.
QSizePolicy::Slider0x00000800AQAbstractSlider instance.
QSizePolicy::SpinBox0x00001000AQAbstractSpinBox instance.
QSizePolicy::TabWidget0x00002000AQTabWidget instance.
QSizePolicy::ToolButton0x00004000AQToolButton instance.

This enum was introduced or modified in Qt 4.3.

The ControlTypes type is a typedef forQFlags<ControlType>. It stores an OR combination of ControlType values.

See alsosetControlType() andcontrolType().

enum QSizePolicy::Policy

This enum describes the various per-dimension sizing types used when constructing aQSizePolicy.

ConstantValueDescription
QSizePolicy::Fixed0TheQWidget::sizeHint() is the only acceptable alternative, so the widget can never grow or shrink (e.g. the vertical direction of a push button).
QSizePolicy::MinimumGrowFlagThe 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::MaximumShrinkFlagThe 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::PreferredGrowFlag | ShrinkFlagThe 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 defaultQWidget policy).
QSizePolicy::ExpandingGrowFlag | ShrinkFlag | ExpandFlagThe 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 horizontal slider).
QSizePolicy::MinimumExpandingGrowFlag | ExpandFlagThe 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 horizontal slider).
QSizePolicy::IgnoredShrinkFlag | GrowFlag | IgnoreFlagThe sizeHint() is ignored. The widget will get as much space as possible.

See alsoPolicyFlag,setHorizontalPolicy(), andsetVerticalPolicy().

enum QSizePolicy::PolicyFlag

These flags are combined together to form the variousPolicy values:

ConstantValueDescription
QSizePolicy::GrowFlag1The widget can grow beyond its size hint if necessary.
QSizePolicy::ExpandFlag2The widget should get as much space as possible.
QSizePolicy::ShrinkFlag4The widget can shrink below its size hint if necessary.
QSizePolicy::IgnoreFlag8The widget's size hint is ignored. The widget will get as much space as possible.

See alsoPolicy.

Member Function Documentation

QSizePolicy::QSizePolicy()

Constructs aQSizePolicy object withFixed as its horizontal and vertical policies.

The policies can be altered using thesetHorizontalPolicy() andsetVerticalPolicy() functions. Use thesetHeightForWidth() function if the preferred height of the widget is dependent on the width of the widget (for example, aQLabel with line wrapping).

See alsosetHorizontalStretch() andsetVerticalStretch().

QSizePolicy::QSizePolicy(Policy horizontal,Policy vertical)

Constructs aQSizePolicy object with the givenhorizontal andvertical policies, andDefaultType as the control type.

UsesetHeightForWidth() if the preferred height of the widget is dependent on the width of the widget (for example, aQLabel with line wrapping).

See alsosetHorizontalStretch() andsetVerticalStretch().

QSizePolicy::QSizePolicy(Policy horizontal,Policy vertical,ControlType type)

Constructs aQSizePolicy object with the givenhorizontal andvertical policies, and the specified controltype.

UsesetHeightForWidth() if the preferred height of the widget is dependent on the width of the widget (for example, aQLabel with line wrapping).

This function was introduced in Qt 4.3.

See alsosetHorizontalStretch(),setVerticalStretch(), andcontrolType().

ControlType QSizePolicy::controlType() const

Returns the control type associated with the widget for which this size policy applies.

This function was introduced in Qt 4.3.

See alsosetControlType().

Qt::Orientations QSizePolicy::expandingDirections() const

Returns whether a widget can make use of more space than theQWidget::sizeHint() function indicates.

A value ofQt::Horizontal orQt::Vertical means that the widget can grow horizontally or vertically (i.e., the horizontal or vertical policy isExpanding orMinimumExpanding), whereasQt::Horizontal |Qt::Vertical means that it can grow in both dimensions.

See alsohorizontalPolicy() andverticalPolicy().

bool QSizePolicy::hasHeightForWidth() const

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

See alsosetHeightForWidth().

bool QSizePolicy::hasWidthForHeight() const

Returns true if the widget's width depends on its height; otherwise returns false.

This function was introduced in Qt 4.8.

See alsosetWidthForHeight().

Policy QSizePolicy::horizontalPolicy() const

Returns the horizontal component of the size policy.

See alsosetHorizontalPolicy(),verticalPolicy(), andhorizontalStretch().

int QSizePolicy::horizontalStretch() const

Returns the horizontal stretch factor of the size policy.

See alsosetHorizontalStretch(),verticalStretch(), andhorizontalPolicy().

void QSizePolicy::setControlType(ControlType type)

Sets the control type associated with the widget for which this size policy applies totype.

The control type specifies the type of the widget for which this size policy applies. It is used by some styles, notablyQMacStyle, to insert proper spacing between widgets. For example, the Mac OS X Aqua guidelines specify that push buttons should be separated by 12 pixels, whereas vertically stacked radio buttons only require 6 pixels.

This function was introduced in Qt 4.3.

See alsocontrolType() andQStyle::layoutSpacing().

void QSizePolicy::setHeightForWidth(bool dependent)

Sets the flag determining whether the widget's preferred height depends on its width, todependent.

See alsohasHeightForWidth() andsetWidthForHeight().

void QSizePolicy::setHorizontalPolicy(Policy policy)

Sets the horizontal component to the givenpolicy.

See alsohorizontalPolicy(),setVerticalPolicy(), andsetHorizontalStretch().

void QSizePolicy::setHorizontalStretch(uchar stretchFactor)

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

See alsohorizontalStretch(),setVerticalStretch(), andsetHorizontalPolicy().

void QSizePolicy::setVerticalPolicy(Policy policy)

Sets the vertical component to the givenpolicy.

See alsoverticalPolicy(),setHorizontalPolicy(), andsetVerticalStretch().

void QSizePolicy::setVerticalStretch(uchar stretchFactor)

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

See alsoverticalStretch(),setHorizontalStretch(), andsetVerticalPolicy().

void QSizePolicy::setWidthForHeight(bool dependent)

Sets the flag determining whether the widget's width depends on its height, todependent.

This is only supported forQGraphicsLayout's subclasses. It is not possible to have a layout with both height-for-width and width-for-height constraints at the same time.

This function was introduced in Qt 4.8.

See alsohasWidthForHeight() andsetHeightForWidth().

void QSizePolicy::transpose()

Swaps the horizontal and vertical policies and stretches.

Policy QSizePolicy::verticalPolicy() const

Returns the vertical component of the size policy.

See alsosetVerticalPolicy(),horizontalPolicy(), andverticalStretch().

int QSizePolicy::verticalStretch() const

Returns the vertical stretch factor of the size policy.

See alsosetVerticalStretch(),horizontalStretch(), andverticalPolicy().

QSizePolicy::operator QVariant() const

Returns aQVariant storing thisQSizePolicy.

bool QSizePolicy::operator!=(constQSizePolicy & other) const

Returns true if this policy is different fromother; otherwise returns false.

See alsooperator==().

bool QSizePolicy::operator==(constQSizePolicy & other) const

Returns true if this policy is equal toother; otherwise returns false.

See alsooperator!=().

Related Non-Members

QDataStream &operator<<(QDataStream & stream, constQSizePolicy & policy)

Writes the sizepolicy to the data streamstream.

This function was introduced in Qt 4.2.

See alsoFormat of the QDataStream operators.

QDataStream &operator>>(QDataStream & stream,QSizePolicy & policy)

Reads the sizepolicy from the data streamstream.

This function was introduced in Qt 4.2.

See alsoFormat of the QDataStream operators.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp