QStackedLayout 類提供每次僅一 Widget 可見的 Widget 堆棧。 更多...
| 頭: | #include <QStackedLayout> |
| qmake: | QT += widgets |
| 繼承: | QLayout |
| enum | StackingMode { StackOne, StackAll } |
| QStackedLayout (QLayout * parentLayout ) | |
| QStackedLayout (QWidget * parent ) | |
| QStackedLayout () | |
| 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 ) |
QStackedLayout 可以用於創建的用戶界麵,類似於某種提供通過 QTabWidget 。還有方便 QStackedWidget 類建立在 QStackedLayout 頂部。
QStackedLayout 可以填充多個子級 Widget (頁麵)。例如:
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 沒有為用戶提供切換頁麵的內在手段。通常,做到這是透過 QComboBox 或 QListWidget 存儲 QStackedLayout 頁麵的標題。例如:
QComboBox *pageComboBox = new QComboBox;
pageComboBox->addItem(tr("Page 1"));
pageComboBox->addItem(tr("Page 2"));
pageComboBox->addItem(tr("Page 3"));
connect(pageComboBox, QOverload<int>::of(&QComboBox::activated),
stackedLayout, &QStackedLayout::setCurrentIndex);
當填充布局時,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 ) |
Constructs a new QStackedLayout and inserts it into the given parentLayout .
Constructs a new QStackedLayout with the given parent .
This layout will install itself on the parent widget and manage the geometry of its children.
Constructs a QStackedLayout with no parent.
This QStackedLayout must be installed on a widget later on to become effective.
另請參閱 addWidget () 和 insertWidget ().
[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 ().
[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 ().
[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 ().
[虛擬]
QStackedLayout::
~QStackedLayout
()
銷毀此 QStackedLayout . Note that the layout's widgets are not destroyed.
[override virtual]
void
QStackedLayout::
addItem
(
QLayoutItem
*
item
)
重實現: QLayout::addItem (QLayoutItem *item).
添加給定 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 ().
返迴當前 Widget,或
nullptr
if there are no widgets in this layout.
另請參閱 currentIndex () 和 setCurrentWidget ().
[override virtual]
bool
QStackedLayout::
hasHeightForWidth
() const
重實現: QLayoutItem::hasHeightForWidth () const.
[override virtual]
int
QStackedLayout::
heightForWidth
(
int
width
) const
重實現: QLayoutItem::heightForWidth (int ) const.
插入給定 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 (int index) const.
[override virtual]
QSize
QStackedLayout::
minimumSize
() const
重實現: QLayout::minimumSize () const.
[override virtual]
void
QStackedLayout::
setGeometry
(const
QRect
&
rect
)
重實現: QLayout::setGeometry (const QRect &r).
[override virtual]
QSize
QStackedLayout::
sizeHint
() const
重實現: QLayoutItem::sizeHint () const.
[override virtual]
QLayoutItem
*QStackedLayout::
takeAt
(
int
index
)
重實現: QLayout::takeAt (int index).
返迴 Widget 按給定
index
,或
nullptr
if there is no widget at the given position.
另請參閱 currentWidget () 和 indexOf ().