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