Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QStackedLayout Class

TheQStackedLayout class provides a stack of widgets where only one widget is visible at a time.More...

Header:#include <QStackedLayout>
Inherits:QLayout

Public Types

enumStackingMode { StackOne, StackAll }

Properties

Public Functions

QStackedLayout()
QStackedLayout(QWidget * parent)
QStackedLayout(QLayout * parentLayout)
~QStackedLayout()
intaddWidget(QWidget * widget)
intcurrentIndex() const
QWidget *currentWidget() const
intinsertWidget(int index, QWidget * widget)
voidsetStackingMode(StackingMode stackingMode)
StackingModestackingMode() const
QWidget *widget(int index) const

Reimplemented Public Functions

virtual voidaddItem(QLayoutItem * item)
virtual intcount() const
virtual QLayoutItem *itemAt(int index) const
virtual QSizeminimumSize() const
virtual voidsetGeometry(const QRect & rect)
virtual QSizesizeHint() const
virtual QLayoutItem *takeAt(int index)
  • 35 public functions inherited fromQLayout
  • 29 public functions inherited fromQObject
  • 17 public functions inherited fromQLayoutItem

Public Slots

voidsetCurrentIndex(int index)
voidsetCurrentWidget(QWidget * widget)
  • 1 public slot inherited fromQObject

Signals

voidcurrentChanged(int index)
voidwidgetRemoved(int index)

Additional Inherited Members

  • 1 static public member inherited fromQLayout
  • 7 static public members inherited fromQObject
  • 4 protected functions inherited fromQLayout
  • 8 protected functions inherited fromQObject

Detailed Description

TheQStackedLayout class provides a stack of widgets where only one widget is visible at a time.

QStackedLayout can be used to create a user interface similar to the one provided byQTabWidget. There is also a convenienceQStackedWidget class built on top ofQStackedLayout.

AQStackedLayout can be populated with a number of child widgets ("pages"). For example:

QWidget*firstPageWidget=newQWidget;QWidget*secondPageWidget=newQWidget;QWidget*thirdPageWidget=newQWidget;QStackedLayout*stackedLayout=newQStackedLayout;    stackedLayout->addWidget(firstPageWidget);    stackedLayout->addWidget(secondPageWidget);    stackedLayout->addWidget(thirdPageWidget);QVBoxLayout*mainLayout=newQVBoxLayout;    mainLayout->addLayout(stackedLayout);    setLayout(mainLayout);

QStackedLayout provides no intrinsic means for the user to switch page. This is typically done through aQComboBox or aQListWidget that stores the titles of theQStackedLayout's pages. For example:

QComboBox*pageComboBox=newQComboBox;    pageComboBox->addItem(tr("Page 1"));    pageComboBox->addItem(tr("Page 2"));    pageComboBox->addItem(tr("Page 3"));    connect(pageComboBox, SIGNAL(activated(int)),            stackedLayout, SLOT(setCurrentIndex(int)));

When populating a layout, the widgets are added to an internal list. TheindexOf() function returns the index of a widget in that list. The widgets can either be added to the end of the list using theaddWidget() function, or inserted at a given index using theinsertWidget() function. TheremoveWidget() function removes the widget at the given index from the layout. The number of widgets contained in the layout, can be obtained using thecount() function.

Thewidget() function returns the widget at a given index position. The index of the widget that is shown on screen is given bycurrentIndex() and can be changed usingsetCurrentIndex(). In a similar manner, the currently shown widget can be retrieved using thecurrentWidget() function, and altered using thesetCurrentWidget() function.

Whenever the current widget in the layout changes or a widget is removed from the layout, thecurrentChanged() andwidgetRemoved() signals are emitted respectively.

See alsoQStackedWidget andQTabWidget.

Member Type Documentation

enum QStackedLayout::StackingMode

This enum specifies how the layout handles its child widgets regarding their visibility.

ConstantValueDescription
QStackedLayout::StackOne0Only the current widget is visible. This is the default.
QStackedLayout::StackAll1All widgets are visible. The current widget is merely raised.

This enum was introduced or modified in Qt 4.4.

Property Documentation

count : constint

This property holds the number of widgets contained in the layout.

Access functions:

virtual intcount() const

See alsocurrentIndex() andwidget().

currentIndex :int

This property holds the index position of the widget that is visible.

The current index is -1 if there is no current widget.

Access functions:

intcurrentIndex() const
voidsetCurrentIndex(int index)

Notifier signal:

voidcurrentChanged(int index)

See alsocurrentWidget() andindexOf().

stackingMode :StackingMode

This property determines the way visibility of child widgets are handled.

The default value isStackOne. Setting the property toStackAll allows you to make use of the layout for overlay widgets that do additional drawing on top of other widgets, for example, graphical editors.

This property was introduced in Qt 4.4.

Access functions:

StackingModestackingMode() const
voidsetStackingMode(StackingMode stackingMode)

Member Function Documentation

QStackedLayout::QStackedLayout()

Constructs aQStackedLayout with no parent.

ThisQStackedLayout must be installed on a widget later on to become effective.

See alsoaddWidget() andinsertWidget().

QStackedLayout::QStackedLayout(QWidget * parent)

Constructs a newQStackedLayout with the givenparent.

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

QStackedLayout::QStackedLayout(QLayout * parentLayout)

Constructs a newQStackedLayout and inserts it into the givenparentLayout.

QStackedLayout::~QStackedLayout()

Destroys thisQStackedLayout. Note that the layout's widgets arenot destroyed.

[virtual]void QStackedLayout::addItem(QLayoutItem * item)

Reimplemented fromQLayout::addItem().

int QStackedLayout::addWidget(QWidget * widget)

Adds the givenwidget to the end of this layout and returns the index position of thewidget.

If theQStackedLayout is empty before this function is called, the givenwidget becomes the current widget.

See alsoinsertWidget(),removeWidget(), andsetCurrentWidget().

QWidget * QStackedLayout::currentWidget() const

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

See alsocurrentIndex() andsetCurrentWidget().

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

Inserts the givenwidget at the givenindex in thisQStackedLayout. Ifindex is out of range, the widget is appended (in which case it is the actual index of thewidget that is returned).

If theQStackedLayout is empty before this function is called, the givenwidget 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.

See alsoaddWidget(),removeWidget(), andsetCurrentWidget().

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

Reimplemented fromQLayout::itemAt().

[virtual]QSize QStackedLayout::minimumSize() const

Reimplemented fromQLayoutItem::minimumSize().

[slot]void QStackedLayout::setCurrentWidget(QWidget * widget)

Sets the current widget to be the specifiedwidget. The new current widget must already be contained in this stacked layout.

See alsosetCurrentIndex() andcurrentWidget().

[virtual]void QStackedLayout::setGeometry(constQRect & rect)

Reimplemented fromQLayoutItem::setGeometry().

[virtual]QSize QStackedLayout::sizeHint() const

Reimplemented fromQLayoutItem::sizeHint().

[virtual]QLayoutItem * QStackedLayout::takeAt(int index)

Reimplemented fromQLayout::takeAt().

QWidget * QStackedLayout::widget(int index) const

Returns the widget at the givenindex, or 0 if there is no widget at the given position.

See alsocurrentWidget() andindexOf().

[signal]void QStackedLayout::widgetRemoved(int index)

This signal is emitted whenever a widget is removed from the layout. The widget'sindex is passed as parameter.

See alsoremoveWidget().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp