|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.core.QObject
com.trolltech.qt.gui.QLayout
com.trolltech.qt.gui.QStackedLayout
public class QStackedLayout
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.
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.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)
Implemented in subclasses to add an arg__1. |
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)
Must be implemented in subclasses to return the layout item at index. |
QSize |
minimumSize()
Returns the minimum size of this layout. |
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)
Implemented in subclasses to set this item's geometry to arg__1. |
QSize |
sizeHint()
Implemented in subclasses to return the preferred size of this item. |
QLayoutItemInterface |
takeAt(int arg__1)
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. |
QWidget |
widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned. |
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.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 |
---|
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.
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.
Constructor Detail |
---|
public QStackedLayout()
Constructs a QStackedLayout with no parent.
This QStackedLayout must be installed on a widget later on to become effective.
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.
public QStackedLayout(QLayout parentLayout)
Constructs a new QStackedLayout and inserts it into the given parentLayout.
Method Detail |
---|
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.
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.
public final QWidget currentWidget()
Returns the current widget, or 0 if there are no widgets in this layout.
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.
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.
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.
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.
public void addItem(QLayoutItemInterface item)
Implemented in subclasses to add an arg__1. How it is added is specific to each subclass.
This function is not usually called in application code. To add a widget to a layout, use the addWidget function; to add a child layout, use the addLayout() function provided by the relevant QLayout subclass.
Note: The ownership of arg__1 is transferred to the layout, and it's the layout's responsibility to delete it.
addItem
in class QLayout
public int count()
Returns the number of widgets contained in the layout.
count
in class QLayout
public QLayoutItemInterface itemAt(int arg__1)
Must be implemented in subclasses to return the layout item at index. If there is no such item, the function must return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.
This function can be used to iterate over a layout. The following code will draw a rectangle for each layout item in the layout structure of the widget.
static void paintLayout(QPainter *painter, QLayoutItem *item) { QLayout *layout = item->layout(); if (layout) { for (int i = 0; i < layout->count(); ++i) paintLayout(painter, layout->itemAt(i)); } painter->drawRect(layout->geometry()); } void MyWidget::paintEvent(QPaintEvent *) { QPainter painter(this); if (layout()) paintLayout(&painter, layout()); }
itemAt
in class QLayout
public QSize minimumSize()
Returns the minimum size of this layout. This is the smallest size that the layout can have while still respecting the specifications.
The returned value doesn't include the space required by QWidget::setContentsMargins() or menuBar.
The default implementation allows unlimited resizing.
minimumSize
in interface QLayoutItemInterface
minimumSize
in class QLayout
public void setGeometry(QRect rect)
Implemented in subclasses to set this item's geometry to arg__1.
setGeometry
in interface QLayoutItemInterface
setGeometry
in class QLayout
public QSize sizeHint()
Implemented in subclasses to return the preferred size of this item.
sizeHint
in interface QLayoutItemInterface
sizeHint
in class QLayout
public QLayoutItemInterface takeAt(int arg__1)
Must be implemented in subclasses to remove the layout item at index from the layout, and return the item. If there is no such item, the function must do nothing and return 0. Items are numbered consecutively from 0. If an item is deleted, other items will be renumbered.
The following code fragment shows a safe way to remove all items from a layout:
QLayoutItem *child; while ((child = layout->takeAt(0)) != 0) { ... delete child; }
takeAt
in class QLayout
public QWidget widget()
If this item is a QWidget, it is returned as a QWidget; otherwise 0 is returned. This function provides type-safe casting.
widget
in interface QLayoutItemInterface
widget
in class QLayout
public static QStackedLayout fromNativePointer(QNativePointer nativePointer)
nativePointer
- the QNativePointer of which object should be returned.
|
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |