Qt 4.8
|
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View. More...
#include <qgraphicslinearlayout.h>
Public Functions | |
void | addItem (QGraphicsLayoutItem *item) |
This convenience function is equivalent to calling insertItem(-1, item). More... | |
void | addStretch (int stretch=1) |
This convenience function is equivalent to calling insertStretch(-1, stretch). More... | |
Qt::Alignment | alignment (QGraphicsLayoutItem *item) const |
Returns the alignment for item. More... | |
int | count () const |
Reimplemented Function More... | |
void | dump (int indent=0) const |
void | insertItem (int index, QGraphicsLayoutItem *item) |
Inserts item into the layout at index, or before any item that is currently at index. More... | |
void | insertStretch (int index, int stretch=1) |
Inserts a stretch of stretch at index, or before any item that is currently at index. More... | |
void | invalidate () |
Reimplemented Function More... | |
QGraphicsLayoutItem * | itemAt (int index) const |
When iterating from 0 and up, it will return the items in the visual arranged order. More... | |
qreal | itemSpacing (int index) const |
Returns the spacing after item at index. More... | |
Qt::Orientation | orientation () const |
Returns the layout orientation. More... | |
QGraphicsLinearLayout (QGraphicsLayoutItem *parent=0) | |
Constructs a QGraphicsLinearLayout instance using Qt::Horizontal orientation. More... | |
QGraphicsLinearLayout (Qt::Orientation orientation, QGraphicsLayoutItem *parent=0) | |
Constructs a QGraphicsLinearLayout instance. More... | |
void | removeAt (int index) |
Removes the item at index without destroying it. More... | |
void | removeItem (QGraphicsLayoutItem *item) |
Removes item from the layout without destroying it. More... | |
void | setAlignment (QGraphicsLayoutItem *item, Qt::Alignment alignment) |
Sets the alignment of item to alignment. More... | |
void | setGeometry (const QRectF &rect) |
Reimplemented Function More... | |
void | setItemSpacing (int index, qreal spacing) |
Sets the spacing after item at index to spacing. More... | |
void | setOrientation (Qt::Orientation orientation) |
Change the layout orientation to orientation. More... | |
void | setSpacing (qreal spacing) |
Sets the layout's spacing to spacing. More... | |
void | setStretchFactor (QGraphicsLayoutItem *item, int stretch) |
Sets the stretch factor for item to stretch. More... | |
QSizeF | sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const |
Reimplemented Function More... | |
qreal | spacing () const |
Returns the layout's spacing. More... | |
int | stretchFactor (QGraphicsLayoutItem *item) const |
Returns the stretch factor for item. More... | |
virtual | ~QGraphicsLinearLayout () |
Destroys the QGraphicsLinearLayout object. More... | |
Public Functions inherited from QGraphicsLayout | |
void | activate () |
Activates the layout, causing all items in the layout to be immediately rearranged. More... | |
void | getContentsMargins (qreal *left, qreal *top, qreal *right, qreal *bottom) const |
Reimplemented Function More... | |
bool | isActivated () const |
Returns true if the layout is currently being activated; otherwise, returns false. More... | |
QGraphicsLayout (QGraphicsLayoutItem *parent=0) | |
Contructs a QGraphicsLayout object. More... | |
void | setContentsMargins (qreal left, qreal top, qreal right, qreal bottom) |
Sets the contents margins to left, top, right and bottom. More... | |
virtual void | updateGeometry () |
Reimplemented Function More... | |
virtual void | widgetEvent (QEvent *e) |
This virtual event handler receives all events for the managed widget. More... | |
~QGraphicsLayout () | |
Destroys the QGraphicsLayout object. More... | |
Public Functions inherited from QGraphicsLayoutItem | |
QRectF | contentsRect () const |
Returns the contents rect in local coordinates. More... | |
QSizeF | effectiveSizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const |
Returns the effective size hint for this QGraphicsLayoutItem. More... | |
QRectF | geometry () const |
Returns the item's geometry (e. More... | |
QGraphicsItem * | graphicsItem () const |
Returns the QGraphicsItem that this layout item represents. More... | |
bool | isLayout () const |
Returns true if this QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges other QGraphicsLayoutItem objects); otherwise returns false. More... | |
qreal | maximumHeight () const |
Returns the maximum height. More... | |
QSizeF | maximumSize () const |
Returns the maximum size. More... | |
qreal | maximumWidth () const |
Returns the maximum width. More... | |
qreal | minimumHeight () const |
Returns the minimum height. More... | |
QSizeF | minimumSize () const |
Returns the minimum size. More... | |
qreal | minimumWidth () const |
Returns the minimum width. More... | |
bool | ownedByLayout () const |
Returns whether a layout should delete this item in its destructor. More... | |
QGraphicsLayoutItem * | parentLayoutItem () const |
Returns the parent of this QGraphicsLayoutItem, or 0 if there is no parent, or if the parent does not inherit from QGraphicsLayoutItem (QGraphicsLayoutItem is often used through multiple inheritance with QObject-derived classes). More... | |
qreal | preferredHeight () const |
Returns the preferred height. More... | |
QSizeF | preferredSize () const |
Returns the preferred size. More... | |
qreal | preferredWidth () const |
Returns the preferred width. More... | |
QGraphicsLayoutItem (QGraphicsLayoutItem *parent=0, bool isLayout=false) | |
Constructs the QGraphicsLayoutItem object. More... | |
void | setMaximumHeight (qreal height) |
Sets the maximum height to height. More... | |
void | setMaximumSize (const QSizeF &size) |
Sets the maximum size to size. More... | |
void | setMaximumSize (qreal w, qreal h) |
This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)). More... | |
void | setMaximumWidth (qreal width) |
Sets the maximum width to width. More... | |
void | setMinimumHeight (qreal height) |
Sets the minimum height to height. More... | |
void | setMinimumSize (const QSizeF &size) |
Sets the minimum size to size. More... | |
void | setMinimumSize (qreal w, qreal h) |
This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)). More... | |
void | setMinimumWidth (qreal width) |
Sets the minimum width to width. More... | |
void | setParentLayoutItem (QGraphicsLayoutItem *parent) |
Sets the parent of this QGraphicsLayoutItem to parent. More... | |
void | setPreferredHeight (qreal height) |
Sets the preferred height to height. More... | |
void | setPreferredSize (const QSizeF &size) |
Sets the preferred size to size. More... | |
void | setPreferredSize (qreal w, qreal h) |
This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)). More... | |
void | setPreferredWidth (qreal width) |
Sets the preferred width to width. More... | |
void | setSizePolicy (const QSizePolicy &policy) |
Sets the size policy to policy. More... | |
void | setSizePolicy (QSizePolicy::Policy hPolicy, QSizePolicy::Policy vPolicy, QSizePolicy::ControlType controlType=QSizePolicy::DefaultType) |
This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)). More... | |
QSizePolicy | sizePolicy () const |
Returns the current size policy. More... | |
virtual | ~QGraphicsLayoutItem () |
Destroys the QGraphicsLayoutItem object. More... | |
Additional Inherited Members | |
Static Public Functions inherited from QGraphicsLayout | |
static bool | instantInvalidatePropagation () |
static void | setInstantInvalidatePropagation (bool enable) |
Protected Functions inherited from QGraphicsLayout | |
void | addChildLayoutItem (QGraphicsLayoutItem *layoutItem) |
This function is a convenience function provided for custom layouts, and will go through all items in the layout and reparent their graphics items to the closest QGraphicsWidget ancestor of the layout. More... | |
QGraphicsLayout (QGraphicsLayoutPrivate &, QGraphicsLayoutItem *) | |
Protected Functions inherited from QGraphicsLayoutItem | |
QGraphicsLayoutItem (QGraphicsLayoutItemPrivate &dd) | |
void | setGraphicsItem (QGraphicsItem *item) |
If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of QGraphicsLayout it should set this value. More... | |
void | setOwnedByLayout (bool ownedByLayout) |
Sets whether a layout should delete this item in its destructor or not. More... | |
Protected Variables inherited from QGraphicsLayoutItem | |
QScopedPointer< QGraphicsLayoutItemPrivate > | d_ptr |
The QGraphicsLinearLayout class provides a horizontal or vertical layout for managing widgets in Graphics View.
The default orientation for a linear layout is Qt::Horizontal. You can choose a vertical orientation either by calling setOrientation(), or by passing Qt::Vertical to QGraphicsLinearLayout's constructor.
The most common way to use QGraphicsLinearLayout is to construct an object on the heap with no parent, add widgets and layouts by calling addItem(), and finally assign the layout to a widget by calling QGraphicsWidget::setLayout().
You can add widgets, layouts, stretches (addStretch(), insertStretch() or setStretchFactor()), and spacings (setItemSpacing()) to a linear layout. The layout takes ownership of the items. In some cases when the layout item also inherits from QGraphicsItem (such as QGraphicsWidget) there will be a ambiguity in ownership because the layout item belongs to two ownership hierarchies. See the documentation of QGraphicsLayoutItem::setOwnedByLayout() how to handle this. You can access each item in the layout by calling count() and itemAt(). Calling removeAt() or removeItem() will remove an item from the layout, without destroying it.
QGraphicsLinearLayout respects each item's size hints and size policies, and when the layout contains more space than the items can fill, each item is arranged according to the layout's alignment for that item. You can set an alignment for each item by calling setAlignment(), and check the alignment for any item by calling alignment(). By default, items are aligned to the top left.
Between the items, the layout distributes some space. The actual amount of space depends on the managed widget's current style, but the common spacing is 4. You can also set your own spacing by calling setSpacing(), and get the current spacing value by calling spacing(). If you want to configure individual spacing for your items, you can call setItemSpacing().
You can assign a stretch factor to each item to control how much space it will get compared to the other items. By default, two identical widgets arranged in a linear layout will have the same size, but if the first widget has a stretch factor of 1 and the second widget has a stretch factor of 2, the first widget will get 1/3 of the available space, and the second will get 2/3.
QGraphicsLinearLayout calculates the distribution of sizes by adding up the stretch factors of all items, and then dividing the available space accordingly. The default stretch factor is 0 for all items; a factor of 0 means the item does not have any defined stretch factor; effectively this is the same as setting the stretch factor to 1. The stretch factor only applies to the available space in the lengthwise direction of the layout (following its orientation). If you want to control both the item's horizontal and vertical stretch, you can use QGraphicsGridLayout instead.
QGraphicsLinearLayout is very similar to QVBoxLayout and QHBoxLayout, but in contrast to these classes, it is used to manage QGraphicsWidget and QGraphicsLayout instead of QWidget and QLayout.
Definition at line 58 of file qgraphicslinearlayout.h.
QGraphicsLinearLayout::QGraphicsLinearLayout | ( | QGraphicsLayoutItem * | parent = 0 | ) |
Constructs a QGraphicsLinearLayout instance using Qt::Horizontal orientation.
parent is passed to QGraphicsLayout's constructor.
Definition at line 200 of file qgraphicslinearlayout.cpp.
QGraphicsLinearLayout::QGraphicsLinearLayout | ( | Qt::Orientation | orientation, |
QGraphicsLayoutItem * | parent = 0 |
||
) |
Constructs a QGraphicsLinearLayout instance.
You can pass the orientation for the layout, either horizontal or vertical, and parent is passed to QGraphicsLayout's constructor.
Definition at line 191 of file qgraphicslinearlayout.cpp.
|
virtual |
Destroys the QGraphicsLinearLayout object.
Definition at line 208 of file qgraphicslinearlayout.cpp.
|
inline |
This convenience function is equivalent to calling insertItem(-1, item).
Definition at line 68 of file qgraphicslinearlayout.h.
|
inline |
This convenience function is equivalent to calling insertStretch(-1, stretch).
Definition at line 69 of file qgraphicslinearlayout.h.
Qt::Alignment QGraphicsLinearLayout::alignment | ( | QGraphicsLayoutItem * | item | ) | const |
Returns the alignment for item.
The default alignment is Qt::AlignTop | Qt::AlignLeft.
The alignment decides how the item is positioned within its assigned space in the case where there's more space available in the layout than the widgets can occupy.
Definition at line 459 of file qgraphicslinearlayout.cpp.
Referenced by setAlignment().
|
virtual |
Reimplemented Function
Implements QGraphicsLayout.
Definition at line 475 of file qgraphicslinearlayout.cpp.
Referenced by ~QGraphicsLinearLayout().
void QGraphicsLinearLayout::dump | ( | int | indent = 0 | ) | const |
Definition at line 557 of file qgraphicslinearlayout.cpp.
Referenced by setGeometry().
void QGraphicsLinearLayout::insertItem | ( | int | index, |
QGraphicsLayoutItem * | item | ||
) |
Inserts item into the layout at index, or before any item that is currently at index.
Definition at line 273 of file qgraphicslinearlayout.cpp.
void QGraphicsLinearLayout::insertStretch | ( | int | index, |
int | stretch = 1 |
||
) |
Inserts a stretch of stretch at index, or before any item that is currently at index.
Definition at line 299 of file qgraphicslinearlayout.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QGraphicsLayout.
Definition at line 547 of file qgraphicslinearlayout.cpp.
Referenced by insertItem(), insertStretch(), removeAt(), removeItem(), setAlignment(), setItemSpacing(), setOrientation(), setSpacing(), and setStretchFactor().
|
virtual |
When iterating from 0 and up, it will return the items in the visual arranged order.
Reimplemented Function
Implements QGraphicsLayout.
Definition at line 488 of file qgraphicslinearlayout.cpp.
Referenced by ~QGraphicsLinearLayout().
qreal QGraphicsLinearLayout::itemSpacing | ( | int | index | ) | const |
Returns the spacing after item at index.
Definition at line 388 of file qgraphicslinearlayout.cpp.
Qt::Orientation QGraphicsLinearLayout::orientation | ( | ) | const |
Returns the layout orientation.
Definition at line 244 of file qgraphicslinearlayout.cpp.
Referenced by setOrientation().
|
virtual |
Removes the item at index without destroying it.
Ownership of the item is transferred to the caller.
Implements QGraphicsLayout.
Definition at line 331 of file qgraphicslinearlayout.cpp.
Referenced by ~QGraphicsLinearLayout().
void QGraphicsLinearLayout::removeItem | ( | QGraphicsLayoutItem * | item | ) |
Removes item from the layout without destroying it.
Ownership of item is transferred to the caller.
Definition at line 314 of file qgraphicslinearlayout.cpp.
void QGraphicsLinearLayout::setAlignment | ( | QGraphicsLayoutItem * | item, |
Qt::Alignment | alignment | ||
) |
Sets the alignment of item to alignment.
If item's alignment changes, the layout is automatically invalidated.
Definition at line 440 of file qgraphicslinearlayout.cpp.
|
virtual |
Reimplemented Function
Reimplemented from QGraphicsLayoutItem.
Definition at line 504 of file qgraphicslinearlayout.cpp.
void QGraphicsLinearLayout::setItemSpacing | ( | int | index, |
qreal | spacing | ||
) |
Sets the spacing after item at index to spacing.
Definition at line 379 of file qgraphicslinearlayout.cpp.
void QGraphicsLinearLayout::setOrientation | ( | Qt::Orientation | orientation | ) |
Change the layout orientation to orientation.
Changing the layout orientation will automatically invalidate the layout.
Definition at line 230 of file qgraphicslinearlayout.cpp.
void QGraphicsLinearLayout::setSpacing | ( | qreal | spacing | ) |
Sets the layout's spacing to spacing.
Spacing refers to the vertical and horizontal distances between items.
Definition at line 353 of file qgraphicslinearlayout.cpp.
void QGraphicsLinearLayout::setStretchFactor | ( | QGraphicsLayoutItem * | item, |
int | stretch | ||
) |
Sets the stretch factor for item to stretch.
If an item's stretch factor changes, this function will invalidate the layout.
Setting stretch to 0 removes the stretch factor from the item, and is effectively equivalent to setting stretch to 1.
Definition at line 403 of file qgraphicslinearlayout.cpp.
|
virtual |
Reimplemented Function
Implements QGraphicsLayoutItem.
Definition at line 535 of file qgraphicslinearlayout.cpp.
qreal QGraphicsLinearLayout::spacing | ( | ) | const |
Returns the layout's spacing.
Spacing refers to the vertical and horizontal distances between items.
Definition at line 370 of file qgraphicslinearlayout.cpp.
int QGraphicsLinearLayout::stretchFactor | ( | QGraphicsLayoutItem * | item | ) | const |
Returns the stretch factor for item.
The default stretch factor is 0, meaning that the item has no assigned stretch factor.
Definition at line 423 of file qgraphicslinearlayout.cpp.
Referenced by setStretchFactor().