返回介绍

QSizePolicy Class

发布于 2019-10-04 15:02:42 字数 9724 浏览 1080 评论 0 收藏 0

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

#include <qsizepolicy.h>

List of all member functions.

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, BothDirections = Horizontally | Vertically, Horizontal = Horizontally, Vertical = Vertically }
  • QSizePolicy ()
  • QSizePolicy ( SizeTypehor, SizeTypever, boolhfw = FALSE )
  • QSizePolicy ( SizeTypehor, SizeTypever, ucharhorStretch, ucharverStretch, boolhfw = FALSE )
  • SizeType horData () const
  • SizeType verData () const
  • bool mayShrinkHorizontally () const
  • bool mayShrinkVertically () const
  • bool mayGrowHorizontally () const
  • bool mayGrowVertically () const
  • ExpandData expanding () const
  • void setHorData ( SizeTyped )
  • void setVerData ( SizeTyped )
  • void setHeightForWidth ( boolb )
  • bool hasHeightForWidth () const
  • bool operator== ( constQSizePolicy&s ) const
  • bool operator!= ( constQSizePolicy&s ) const
  • uint horStretch () const
  • uint verStretch () const
  • void setHorStretch ( ucharsf )
  • void setVerStretch ( ucharsf )

Detailed Description

The QSizePolicy 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.

Widgets that reimplement QWidget::sizePolicy() return a QSizePolicy that describes the horizontal and vertical resizing policy they prefer when being laid out. Only one of the constructors is of interest in most applications.

QSizePolicy contains two independent SizeType objects; 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 per-dimension SizeType objects are set in the usual constructor and can be queried using a variety of functions, none of which are really interesting to application programmers.

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

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.
  • 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().

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).
  • 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).
  • 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).
  • 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.

In any case, QLayout never shrinks a widget below the QWidget::minimumSizeHint().


Member Function Documentation

QSizePolicy::QSizePolicy ()

Default constructor; produces a minimally initialized QSizePolicy.

QSizePolicy::QSizePolicy ( SizeTypehor, SizeTypever, boolhfw = 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 ( SizeTypehor, SizeTypever, ucharhorStretch, ucharverStretch, boolhfw = 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 a value indicating whether the widget can make use of extra space (i.e. if it "wants" to grow) horizontally and/or vertically.

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!= ( constQSizePolicy&s ) const

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

See also operator==().

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

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

See also operator!=().

void QSizePolicy::setHeightForWidth ( boolb )

Sets the hasHeightForWidth() flag to b.

See also hasHeightForWidth().

void QSizePolicy::setHorData ( SizeTyped )

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

See also horData() and setVerData().

void QSizePolicy::setHorStretch ( ucharsf )

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

See also horStretch() and setVerStretch().

void QSizePolicy::setVerData ( SizeTyped )

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

See also verData() and setHorData().

void QSizePolicy::setVerStretch ( ucharsf )

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

See also verStretch() and setHorStretch().

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().

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
    我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
    原文