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

QStackedWidget Class

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

Header:#include <QStackedWidget>
Inherits:QFrame

Properties

  • 6 properties inherited fromQFrame
  • 58 properties inherited fromQWidget
  • 1 property inherited fromQObject

Public Functions

QStackedWidget(QWidget * parent = 0)
~QStackedWidget()
intaddWidget(QWidget * widget)
intcount() const
intcurrentIndex() const
QWidget *currentWidget() const
intindexOf(QWidget * widget) const
intinsertWidget(int index, QWidget * widget)
voidremoveWidget(QWidget * widget)
QWidget *widget(int index) const
  • 14 public functions inherited fromQFrame
  • 220 public functions inherited fromQWidget
  • 29 public functions inherited fromQObject
  • 12 public functions inherited fromQPaintDevice

Public Slots

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

Signals

voidcurrentChanged(int index)
voidwidgetRemoved(int index)

Reimplemented Protected Functions

virtual boolevent(QEvent * e)
  • 3 protected functions inherited fromQFrame
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 3 protected functions inherited fromQFrame
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice
  • 1 protected slot inherited fromQWidget

Detailed Description

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

QStackedWidget can be used to create a user interface similar to the one provided byQTabWidget. It is a convenience layout widget built on top of theQStackedLayout class.

LikeQStackedLayout,QStackedWidget can be constructed and populated with a number of child widgets ("pages"):

QWidget*firstPageWidget=newQWidget;QWidget*secondPageWidget=newQWidget;QWidget*thirdPageWidget=newQWidget;QStackedWidget*stackedWidget=newQStackedWidget;    stackedWidget->addWidget(firstPageWidget);    stackedWidget->addWidget(secondPageWidget);    stackedWidget->addWidget(thirdPageWidget);QVBoxLayout*layout=newQVBoxLayout;    layout->addWidget(stackedWidget);    setLayout(layout);

QStackedWidget provides no intrinsic means for the user to switch page. This is typically done through aQComboBox or aQListWidget that stores the titles of theQStackedWidget'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)),            stackedWidget, SLOT(setCurrentIndex(int)));

When populating a stacked widget, 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 a widget from the stacked widget. The number of widgets contained in the stacked widget, 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 stacked widget changes or a widget is removed from the stacked widget, thecurrentChanged() andwidgetRemoved() signals are emitted respectively.

See alsoQStackedLayout,QTabWidget, andConfig Dialog Example.

Property Documentation

count : constint

This property holds the number of widgets contained by this stacked widget.

By default, this property contains a value of 0.

Access functions:

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.

By default, this property contains a value of -1 because the stack is initially empty.

Access functions:

intcurrentIndex() const
voidsetCurrentIndex(int index)

Notifier signal:

voidcurrentChanged(int index)

See alsocurrentWidget() andindexOf().

Member Function Documentation

QStackedWidget::QStackedWidget(QWidget * parent = 0)

Constructs aQStackedWidget with the givenparent.

See alsoaddWidget() andinsertWidget().

QStackedWidget::~QStackedWidget()

Destroys this stacked widget, and frees any allocated resources.

int QStackedWidget::addWidget(QWidget * widget)

Appends the givenwidget to theQStackedWidget and returns the index position. Ownership ofwidget is passed on to theQStackedWidget.

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

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

QWidget * QStackedWidget::currentWidget() const

Returns the current widget, or 0 if there are no child widgets.

See alsocurrentIndex() andsetCurrentWidget().

[virtual protected]bool QStackedWidget::event(QEvent * e)

Reimplemented fromQObject::event().

int QStackedWidget::indexOf(QWidget * widget) const

Returns the index of the givenwidget, or -1 if the givenwidget is not a child of theQStackedWidget.

See alsocurrentIndex() andwidget().

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

Inserts the givenwidget at the givenindex in theQStackedWidget. Ownership ofwidget is passed on to theQStackedWidget. Ifindex is out of range, thewidget is appended (in which case it is the actual index of thewidget that is returned).

If theQStackedWidget was 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().

void QStackedWidget::removeWidget(QWidget * widget)

Removeswidget from theQStackedWidget. i.e.,widget isnot deleted but simply removed from the stacked layout, causing it to be hidden.

Note: Ownership ofwidget reverts to the application.

See alsoaddWidget(),insertWidget(), andcurrentWidget().

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

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

See alsocurrentWidget() andsetCurrentIndex().

QWidget * QStackedWidget::widget(int index) const

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

See alsocurrentWidget() andindexOf().

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

This signal is emitted whenever a widget is removed. 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