Qt Jambi Home

com.trolltech.qt.gui
Class QStackedLayout

java.lang.Object
  extended by com.trolltech.qt.QSignalEmitter
      extended by com.trolltech.qt.QtJambiObject
          extended by com.trolltech.qt.core.QObject
              extended by com.trolltech.qt.gui.QLayout
                  extended by com.trolltech.qt.gui.QStackedLayout
All Implemented Interfaces:
QLayoutItemInterface, QtJambiInterface

public class QStackedLayout
extends QLayout

The QStackedLayout 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 by QTabWidget. There is also a convenience 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 or a 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)));

When populating a layout, the widgets are added to an internal list. The 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 function. The 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 function.

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 function, and altered using the setCurrentWidget function.

Whenever the current widget in the layout changes or a widget is removed from the layout, the currentChanged and widgetRemoved signals are emitted respectively.

See Also:
QStackedWidget, QTabWidget

Nested Class Summary
 
Nested classes/interfaces inherited from class com.trolltech.qt.gui.QLayout
QLayout.SizeConstraint
 
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter
QSignalEmitter.AbstractSignal, QSignalEmitter.Signal0, QSignalEmitter.Signal1<A>, QSignalEmitter.Signal2<A,B>, QSignalEmitter.Signal3<A,B,C>, QSignalEmitter.Signal4<A,B,C,D>, QSignalEmitter.Signal5<A,B,C,D,E>, QSignalEmitter.Signal6<A,B,C,D,E,F>, QSignalEmitter.Signal7<A,B,C,D,E,F,G>, QSignalEmitter.Signal8<A,B,C,D,E,F,G,H>, QSignalEmitter.Signal9<A,B,C,D,E,F,G,H,I>
 
Field Summary
 QSignalEmitter.Signal1<java.lang.Integer> currentChanged
          This signal is emitted whenever the current widget in the layout changes.
 QSignalEmitter.Signal1<java.lang.Integer> widgetRemoved
          This signal is emitted whenever a widget is removed from the layout.
 
Constructor Summary
QStackedLayout()
          Constructs a QStackedLayout with no parent.
QStackedLayout(QLayout parentLayout)
          Constructs a new QStackedLayout and inserts it into the given parentLayout.
QStackedLayout(QWidget parent)
          Constructs a new QStackedLayout with the given parent.
 
Method Summary
 void addItem(QLayoutItemInterface item)
          This function is reimplemented for internal reasons.
 int addStackedWidget(QWidget w)
          Adds the given w to the end of this layout and returns the index position of the w.
 int count()
          Returns the number of widgets contained in the layout.
 int currentIndex()
          Returns the index position of the widget that is visible.
 QWidget currentWidget()
          Returns the current widget, or 0 if there are no widgets in this layout.
static QStackedLayout fromNativePointer(QNativePointer nativePointer)
          This function returns the QStackedLayout instance pointed to by nativePointer
 int insertWidget(int index, QWidget w)
          Inserts the given w at the given index in this QStackedLayout.
 QLayoutItemInterface itemAt(int arg__1)
          This function is reimplemented for internal reasons.
 QSize minimumSize()
          This function is reimplemented for internal reasons.
 void setCurrentIndex(int index)
          Sets the index position of the widget that is visible to index.
 void setCurrentWidget(QWidget w)
          Sets the current widget to be the specified w.
 void setGeometry(QRect rect)
          This function is reimplemented for internal reasons.
 QSize sizeHint()
          This function is reimplemented for internal reasons.
 QLayoutItemInterface takeAt(int arg__1)
          This function is reimplemented for internal reasons.
 QWidget widget()
          This function is reimplemented for internal reasons.
 QWidget widget(int arg__1)
          Returns the widget at the given arg__1, or 0 if there is no widget at the given position.
 
Methods inherited from class com.trolltech.qt.gui.QLayout
activate, addChildLayout, addChildWidget, addWidget, alignment, alignmentRect, childEvent, closestAcceptableSize, contentsRect, controlTypes, expandingDirections, geometry, getContentsMargins, hasHeightForWidth, heightForWidth, indexOf, invalidate, isEmpty, isEnabled, layout, maximumSize, menuBar, minimumHeightForWidth, parentWidget, removeItem, removeWidget, setAlignment, setAlignment, setAlignment, setAlignment, setAlignment, setContentsMargins, setContentsMargins, setEnabled, setMargin, setMenuBar, setSizeConstraint, setWidgetSpacing, sizeConstraint, spacerItem, totalHeightForWidth, totalMaximumSize, totalMinimumSize, totalSizeHint, update, widgetEvent, widgetSpacing
 
Methods inherited from class com.trolltech.qt.core.QObject
blockSignals, children, connectSlotsByName, customEvent, disposeLater, dumpObjectInfo, dumpObjectTree, dynamicPropertyNames, event, eventFilter, findChild, findChild, findChild, findChildren, findChildren, findChildren, findChildren, installEventFilter, isWidgetType, killTimer, moveToThread, objectName, parent, property, removeEventFilter, setObjectName, setParent, setProperty, signalsBlocked, startTimer, thread, timerEvent
 
Methods inherited from class com.trolltech.qt.QtJambiObject
dispose, disposed, finalize, reassignNativeResources, tr, tr, tr
 
Methods inherited from class com.trolltech.qt.QSignalEmitter
disconnect, disconnect, signalSender
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface com.trolltech.qt.QtJambiInterface
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership
 

Field Detail

currentChanged

public final QSignalEmitter.Signal1<java.lang.Integer> currentChanged

This signal is emitted whenever the current widget in the layout changes. The index specifies the index of the new current widget.

Compatible Slot Signatures:
void mySlot(int index)
void mySlot()
See Also:
currentWidget, setCurrentWidget


widgetRemoved

public final QSignalEmitter.Signal1<java.lang.Integer> widgetRemoved

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

Compatible Slot Signatures:
void mySlot(int index)
void mySlot()
See Also:
removeWidget

Constructor Detail

QStackedLayout

public QStackedLayout(QWidget parent)

Constructs a new QStackedLayout with the given parent.

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


QStackedLayout

public QStackedLayout(QLayout parentLayout)

Constructs a new QStackedLayout and inserts it into the given parentLayout.


QStackedLayout

public QStackedLayout()

Constructs a QStackedLayout with no parent.

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

See Also:
addWidget, insertWidget
Method Detail

addStackedWidget

public final int addStackedWidget(QWidget w)

Adds the given w to the end of this layout and returns the index position of the w.

If the QStackedLayout is empty before this function is called, the given w becomes the current widget.

See Also:
insertWidget, removeWidget, setCurrentWidget

currentIndex

public final int currentIndex()

Returns the index position of the widget that is visible.

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

See Also:
setCurrentIndex, currentWidget, indexOf

currentWidget

public final QWidget currentWidget()

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

See Also:
currentIndex, setCurrentWidget

insertWidget

public final int insertWidget(int index,
                              QWidget w)

Inserts the given w at the given index in this QStackedLayout. If index is out of range, the widget is appended (in which case it is the actual index of the w that is returned).

If the QStackedLayout is empty before this function is called, the given w 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 Also:
addWidget, removeWidget, setCurrentWidget

setCurrentIndex

public final void setCurrentIndex(int index)

Sets the index position of the widget that is visible to index.

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

See Also:
currentIndex, currentWidget, indexOf

setCurrentWidget

public final void setCurrentWidget(QWidget w)

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

See Also:
setCurrentIndex, currentWidget

widget

public final QWidget widget(int arg__1)

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

See Also:
currentWidget, indexOf

addItem

public void addItem(QLayoutItemInterface item)

This function is reimplemented for internal reasons.

Specified by:
addItem in class QLayout
See Also:
addWidget, QBoxLayout::addLayout, QGridLayout::addLayout

count

public int count()

Returns the number of widgets contained in the layout.

Specified by:
count in class QLayout
See Also:
currentIndex, widget

itemAt

public QLayoutItemInterface itemAt(int arg__1)

This function is reimplemented for internal reasons.

Specified by:
itemAt in class QLayout
See Also:
count, takeAt

minimumSize

public QSize minimumSize()

This function is reimplemented for internal reasons.

Specified by:
minimumSize in interface QLayoutItemInterface
Overrides:
minimumSize in class QLayout

setGeometry

public void setGeometry(QRect rect)

This function is reimplemented for internal reasons.

Specified by:
setGeometry in interface QLayoutItemInterface
Specified by:
setGeometry in class QLayout
See Also:
geometry

sizeHint

public QSize sizeHint()

This function is reimplemented for internal reasons.

Specified by:
sizeHint in interface QLayoutItemInterface
Specified by:
sizeHint in class QLayout

takeAt

public QLayoutItemInterface takeAt(int arg__1)

This function is reimplemented for internal reasons.

Specified by:
takeAt in class QLayout
See Also:
itemAt, count

widget

public QWidget widget()

This function is reimplemented for internal reasons.

Specified by:
widget in interface QLayoutItemInterface
Overrides:
widget in class QLayout

fromNativePointer

public static QStackedLayout fromNativePointer(QNativePointer nativePointer)
This function returns the QStackedLayout instance pointed to by nativePointer

Parameters:
nativePointer - the QNativePointer of which object should be returned.

Qt Jambi Home