QStackedLayout 類

The QStackedLayout 類提供每次僅一 Widget 可見的小部件堆棧。 更多...

頭: #include <QStackedLayout>
qmake: QT += widgets
繼承: QLayout

公共類型

enum StackingMode { StackOne, StackAll }

特性

公共函數

QStackedLayout ()
QStackedLayout (QWidget * parent )
QStackedLayout (QLayout * parentLayout )
~QStackedLayout ()
int addWidget (QWidget * widget )
int currentIndex () const
QWidget * currentWidget () const
int insertWidget (int index , QWidget * widget )
void setStackingMode (StackingMode stackingMode )
StackingMode stackingMode () const
QWidget * widget (int index ) const

重實現公共函數

virtual void addItem (QLayoutItem * item )
virtual int count () const
virtual bool hasHeightForWidth () const
virtual int heightForWidth (int width ) const
virtual QLayoutItem * itemAt (int index ) const
virtual QSize minimumSize () const
virtual void setGeometry (const QRect & rect )
virtual QSize sizeHint () const
virtual QLayoutItem * takeAt (int index )

公共槽

void setCurrentIndex (int index )
void setCurrentWidget (QWidget * widget )

信號

void currentChanged (int index )
void widgetRemoved (int index )

額外繼承成員

詳細描述

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 .

成員類型文檔編製

enum QStackedLayout:: StackingMode

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 引入或被修改。

特性文檔編製

count : const int

This property holds the number of widgets contained in the layout

訪問函數:

virtual int count () const

另請參閱 currentIndex () 和 widget ().

currentIndex : int

此特性保持可見 Widget 的索引位置

當前索引為 -1,若沒有當前 Widget。

訪問函數:

int currentIndex () const
void setCurrentIndex (int index )

通知程序信號:

void currentChanged (int index )

另請參閱 currentWidget () 和 indexOf ().

stackingMode : StackingMode

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 引入。

訪問函數:

StackingMode stackingMode () const
void setStackingMode (StackingMode stackingMode )

成員函數文檔編製

QStackedLayout:: QStackedLayout ()

構造 QStackedLayout with no parent.

This QStackedLayout must be installed on a widget later on to become effective.

另請參閱 addWidget () 和 insertWidget ().

QStackedLayout:: QStackedLayout ( QWidget * parent )

構造新的 QStackedLayout 采用給定 parent .

This layout will install itself on the parent widget and manage the geometry of its children.

QStackedLayout:: QStackedLayout ( QLayout * parentLayout )

構造新的 QStackedLayout 並將其插入給定 parentLayout .

QStackedLayout:: ~QStackedLayout ()

銷毀此 QStackedLayout . Note that the layout's widgets are not destroyed.

[虛擬] void QStackedLayout:: addItem ( QLayoutItem * item )

重實現自 QLayout::addItem ().

int QStackedLayout:: addWidget ( QWidget * widget )

添加給定 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 ().

QWidget *QStackedLayout:: currentWidget () const

Returns the current widget, or 0 if there are no widgets in this layout.

另請參閱 currentIndex () 和 setCurrentWidget ().

[虛擬] bool QStackedLayout:: hasHeightForWidth () const

重實現自 QLayoutItem::hasHeightForWidth ().

[虛擬] int QStackedLayout:: heightForWidth ( int width ) const

重實現自 QLayoutItem::heightForWidth ().

int QStackedLayout:: insertWidget ( int index , QWidget * widget )

插入給定 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 ().

[虛擬] QLayoutItem *QStackedLayout:: itemAt ( int index ) const

重實現自 QLayout::itemAt ().

[虛擬] QSize QStackedLayout:: minimumSize () const

重實現自 QLayoutItem::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 ().

[虛擬] void QStackedLayout:: setGeometry (const QRect & rect )

重實現自 QLayoutItem::setGeometry ().

[虛擬] QSize QStackedLayout:: sizeHint () const

重實現自 QLayoutItem::sizeHint ().

[虛擬] QLayoutItem *QStackedLayout:: takeAt ( int index )

重實現自 QLayout::takeAt ().

QWidget *QStackedLayout:: widget ( int index ) const

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