QLayoutItem 類提供抽象項為 QLayout 操縱。 更多...
| 頭: | #include <QLayoutItem> |
| qmake: | QT += widgets |
| 繼承者: |
| QLayoutItem (Qt::Alignment alignment = Qt::Alignment()) | |
| virtual | ~QLayoutItem () |
| Qt::Alignment | alignment () const |
| virtual QSizePolicy::ControlTypes | controlTypes () const |
| virtual Qt::Orientations | expandingDirections () const = 0 |
| virtual QRect | geometry () const = 0 |
| virtual bool | hasHeightForWidth () const |
| virtual int | heightForWidth ( int ) const |
| virtual void | invalidate () |
| virtual bool | isEmpty () const = 0 |
| virtual QLayout * | layout () |
| virtual QSize | maximumSize () const = 0 |
| virtual int | minimumHeightForWidth (int w ) const |
| virtual QSize | minimumSize () const = 0 |
| void | setAlignment (Qt::Alignment alignment ) |
| virtual void | setGeometry (const QRect & r ) = 0 |
| virtual QSize | sizeHint () const = 0 |
| virtual QSpacerItem * | spacerItem () |
| virtual QWidget * | widget () |
這被用於自定義布局。
純虛函數的提供以返迴布局有關信息,包括: sizeHint (), minimumSize (), maximumSize () 及 expanding()。
可以設置和檢索布局幾何體采用 setGeometry () 和 geometry (),且其對齊采用 setAlignment () 和 alignment ().
isEmpty () 返迴布局項目是否為空。若具體項是 QWidget ,它可以被檢索使用 widget ()。同樣,對於 layout () 和 spacerItem ().
某些布局的寬度和高度是相互依賴的。這些可以被錶達,使用 hasHeightForWidth (), heightForWidth (),和 minimumHeightForWidth ()。更多解釋見 Qt 季刊 文章 交易高度為寬度 .
另請參閱 QLayout .
構造布局項采用 alignment 。並非所有子類都支持對齊。
[虛擬]
QLayoutItem::
~QLayoutItem
()
銷毀 QLayoutItem .
返迴此項的對齊方式。
另請參閱 setAlignment ().
[虛擬]
QSizePolicy::ControlTypes
QLayoutItem::
controlTypes
() const
返迴布局項控件類型。對於 QWidgetItem ,控件類型來自 Widget 的大小策略;對於 QLayoutItem ,控件類型派生自布局內容。
另請參閱 QSizePolicy::controlType ().
[pure virtual]
Qt::Orientations
QLayoutItem::
expandingDirections
() const
返迴此布局項是否可以利用更多空間相比 sizeHint ()。值 Qt::Vertical or Qt::Horizontal 意味著隻想按 1 維增長,而 Qt::Vertical | Qt::Horizontal 意味著想要按 2 維增長。
[pure virtual]
QRect
QLayoutItem::
geometry
() const
返迴此布局項所涵蓋的矩形。
另請參閱 setGeometry ().
[虛擬]
bool
QLayoutItem::
hasHeightForWidth
() const
返迴
true
若此布局的首選高度從屬其寬度;否則返迴
false
。默認實現返迴 false。
重實現此函數在支持高度為寬度的布局管理器中。
另請參閱 heightForWidth () 和 QWidget::heightForWidth ().
[虛擬]
int
QLayoutItem::
heightForWidth
(
int
) const
返迴此布局項的首選高度 (未在此默認實現中使用),給定寬度。
默認實現返迴 -1,指示首選高度獨立於項寬度。使用函數 hasHeightForWidth () 通常比調用此函數快得多和測試為 -1。
重實現此函數在支持高度為寬度的布局管理器中。典型實現看起來像這樣:
int MyLayout::heightForWidth(int w) const { if (cache_dirty || cached_width != w) { MyLayout *that = const_cast<MyLayout *>(this); int h = calculateHeightForWidth(w); that->cached_hfw = h; return h; } return cached_hfw; }
緩存是強烈推薦的;沒有它,布局將花費指數級的時間。
另請參閱 hasHeightForWidth ().
[虛擬]
void
QLayoutItem::
invalidate
()
使此布局項中的任何緩存信息無效。
[pure virtual]
bool
QLayoutItem::
isEmpty
() const
在子類中實現以返迴此項是否為空 (即:它是否包含任何 Widget)。
[虛擬]
QLayout
*QLayoutItem::
layout
()
若此項是
QLayout
,它被返迴作為
QLayout
;否則
nullptr
被返迴。此函數提供類型安全的鑄造。
另請參閱 spacerItem () 和 widget ().
[pure virtual]
QSize
QLayoutItem::
maximumSize
() const
在子類中實現以返迴此項的最大尺寸。
[虛擬]
int
QLayoutItem::
minimumHeightForWidth
(
int
w
) const
返迴此 Widget 所需的最小高度對於給定寬度 w 。默認實現隻需返迴 heightForWidth ( w ).
[pure virtual]
QSize
QLayoutItem::
minimumSize
() const
在子類中實現以返迴此項的最小尺寸。
把此項的對齊方式設為 alignment .
注意: 項對齊的支持僅通過 QLayoutItem 子類,哪裏有視覺效果。除瞭 QSpacerItem ,為布局提供空白空間,所有公共 Qt 類繼承 QLayoutItem 支持項對齊。
另請參閱 alignment ().
[pure virtual]
void
QLayoutItem::
setGeometry
(const
QRect
&
r
)
在子類中實現以將此項的幾何體設為 r .
另請參閱 geometry ().
[pure virtual]
QSize
QLayoutItem::
sizeHint
() const
在子類中實現以返迴此項的首選大小。
[虛擬]
QSpacerItem
*QLayoutItem::
spacerItem
()
若此項是
QSpacerItem
,它被返迴作為
QSpacerItem
;否則
nullptr
被返迴。此函數提供類型安全的鑄造。
[虛擬]
QWidget
*QLayoutItem::
widget
()
若此項管理
QWidget
,返迴該 Widget。否則,
nullptr
被返迴。
注意: 當函數 layout () 和 spacerItem () 履行鑄造時,此函數返迴另一對象: QLayout and QSpacerItem 繼承 QLayoutItem ,而 QWidget 不會。
另請參閱 layout () 和 spacerItem ().