The QStackedLayout 類提供每次僅一 Widget 可見的小部件堆棧。 更多...
| 頭: | #include <QStackedLayout> |
| qmake: | QT += widgets |
| 繼承: | QLayout |
| enum | StackingMode { StackOne, StackAll } |
| QStackedLayout () | |
| QStackedLayout (QWidget * parent ) | |
| QStackedLayout (QLayout * parentLayout ) | |
| virtual | ~QStackedLayout () |
| int | addWidget (QWidget * widget ) |
| int | currentIndex () const |
| QWidget * | currentWidget () const |
| int | insertWidget (int index , QWidget * widget ) |
| void | setStackingMode (QStackedLayout::StackingMode stackingMode ) |
| QStackedLayout::StackingMode | stackingMode () const |
| QWidget * | widget (int index ) const |
| virtual void | addItem (QLayoutItem * item ) override |
| virtual int | count () const override |
| virtual bool | hasHeightForWidth () const override |
| virtual int | heightForWidth (int width ) const override |
| virtual QLayoutItem * | itemAt (int index ) const override |
| virtual QSize | minimumSize () const override |
| virtual void | setGeometry (const QRect & rect ) override |
| virtual QSize | sizeHint () const override |
| virtual QLayoutItem * | takeAt (int index ) override |
| void | setCurrentIndex (int index ) |
| void | setCurrentWidget (QWidget * widget ) |
| void | currentChanged (int index ) |
| void | widgetRemoved (int index ) |
| const QMetaObject | staticMetaObject |
The QStackedLayout 類提供每次僅一 Widget 可見的小部件堆棧。
QStackedLayout can be used to create a user interface similar to the one provided by QTabWidget 。還有方便 QStackedWidget class built on top of QStackedLayout .
A QStackedLayout can be populated with a number of child widgets ("pages"). For example:
QWidget *firstPageWidget = new QWidget;
QWidget *secondPageWidget = new QWidget;
QWidget *thirdPageWidget = new QWidget;
QStackedLayout *stackedLayout = new QStackedLayout;
stackedLayout->addWidget(firstPageWidget);
stackedLayout->addWidget(secondPageWidget);
stackedLayout->addWidget(thirdPageWidget);
QVBoxLayout *mainLayout = new QVBoxLayout;
mainLayout->addLayout(stackedLayout);
setLayout(mainLayout);
QStackedLayout provides no intrinsic means for the user to switch page. This is typically done through a QComboBox 或 QListWidget that stores the titles of the QStackedLayout 's pages. For example:
QComboBox *pageComboBox = new QComboBox;
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
connect(pageComboBox, SIGNAL(activated(int)),
stackedLayout, SLOT(setCurrentIndex(int)));
當填充布局時,Widget 會被添加到內部列錶中。 indexOf () function returns the index of a widget in that list. The widgets can either be added to the end of the list using the addWidget () function, or inserted at a given index using the insertWidget () 函數。 removeWidget () function removes the widget at the given index from the layout. The number of widgets contained in the layout, can be obtained using the count () 函數。
The widget () function returns the widget at a given index position. The index of the widget that is shown on screen is given by currentIndex () and can be changed using setCurrentIndex (). In a similar manner, the currently shown widget can be retrieved using the currentWidget () 函數,和變更使用 setCurrentWidget () 函數。
Whenever the current widget in the layout changes or a widget is removed from the layout, the currentChanged () 和 widgetRemoved () signals are emitted respectively.
另請參閱 QStackedWidget and QTabWidget .
This enum specifies how the layout handles its child widgets regarding their visibility.
| 常量 | 值 | 描述 |
|---|---|---|
QStackedLayout::StackOne
|
0
|
Only the current widget is visible. This is the default. |
QStackedLayout::StackAll
|
1
|
All widgets are visible. The current widget is merely raised. |
該枚舉在 Qt 4.4 引入或被修改。
This property holds the number of widgets contained in the layout
訪問函數:
| virtual int | count () const override |
另請參閱 currentIndex () 和 widget ().
此特性保持可見 Widget 的索引位置
當前索引為 -1,若沒有當前 Widget。
訪問函數:
| int | currentIndex () const |
| void | setCurrentIndex (int index ) |
通知程序信號:
| void | currentChanged (int index ) |
另請參閱 currentWidget () 和 indexOf ().
determines the way visibility of child widgets are handled.
默認值為 StackOne . Setting the property to StackAll allows you to make use of the layout for overlay widgets that do additional drawing on top of other widgets, for example, graphical editors.
該特性在 Qt 4.4 引入。
訪問函數:
| QStackedLayout::StackingMode | stackingMode () const |
| void | setStackingMode (QStackedLayout::StackingMode stackingMode ) |
構造 QStackedLayout with no parent.
This QStackedLayout must be installed on a widget later on to become effective.
另請參閱 addWidget () 和 insertWidget ().
構造新的 QStackedLayout 采用給定 parent .
This layout will install itself on the parent widget and manage the geometry of its children.
構造新的 QStackedLayout 並將其插入給定 parentLayout .
[虛擬]
QStackedLayout::
~QStackedLayout
()
銷毀此 QStackedLayout . Note that the layout's widgets are not destroyed.
[override virtual]
void
QStackedLayout::
addItem
(
QLayoutItem
*
item
)
重實現自 QLayout::addItem ().
添加給定 widget to the end of this layout and returns the index position of the widget .
若 QStackedLayout is empty before this function is called, the given widget becomes the current widget.
另請參閱 insertWidget (), removeWidget (),和 setCurrentWidget ().
[signal]
void
QStackedLayout::
currentChanged
(
int
index
)
This signal is emitted whenever the current widget in the layout changes. The index specifies the index of the new current widget, or -1 if there isn't a new one (for example, if there are no widgets in the QStackedLayout )
注意: 通知程序信號對於特性 currentIndex .
另請參閱 currentWidget () 和 setCurrentWidget ().
Returns the current widget, or 0 if there are no widgets in this layout.
另請參閱 currentIndex () 和 setCurrentWidget ().
[override virtual]
bool
QStackedLayout::
hasHeightForWidth
() const
重實現自 QLayoutItem::hasHeightForWidth ().
[override virtual]
int
QStackedLayout::
heightForWidth
(
int
width
) const
重實現自 QLayoutItem::heightForWidth ().
插入給定 widget 在給定 index 在此 QStackedLayout 。若 index is out of range, the widget is appended (in which case it is the actual index of the widget that is returned).
若 QStackedLayout is empty before this function is called, the given widget becomes the current widget.
Inserting a new widget at an index less than or equal to the current index will increment the current index, but keep the current widget.
另請參閱 addWidget (), removeWidget (),和 setCurrentWidget ().
[override virtual]
QLayoutItem
*QStackedLayout::
itemAt
(
int
index
) const
重實現自 QLayout::itemAt ().
[override virtual]
QSize
QStackedLayout::
minimumSize
() const
重實現自 QLayout::minimumSize ().
[slot]
void
QStackedLayout::
setCurrentWidget
(
QWidget
*
widget
)
Sets the current widget to be the specified widget . The new current widget must already be contained in this stacked layout.
另請參閱 setCurrentIndex () 和 currentWidget ().
[override virtual]
void
QStackedLayout::
setGeometry
(const
QRect
&
rect
)
重實現自 QLayout::setGeometry ().
[override virtual]
QSize
QStackedLayout::
sizeHint
() const
重實現自 QLayoutItem::sizeHint ().
[override virtual]
QLayoutItem
*QStackedLayout::
takeAt
(
int
index
)
重實現自 QLayout::takeAt ().
返迴 Widget 按給定 index , or 0 if there is no widget at the given position.
另請參閱 currentWidget () 和 indexOf ().
[signal]
void
QStackedLayout::
widgetRemoved
(
int
index
)
This signal is emitted whenever a widget is removed from the layout. The widget's index is passed as parameter.
另請參閱 removeWidget ().