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

QGraphicsLayout Class

TheQGraphicsLayout class provides the base class for all layouts in Graphics View.More...

Header:#include <QGraphicsLayout>
Since: Qt 4.4
Inherits:QGraphicsLayoutItem
Inherited By:

QGraphicsAnchorLayout,QGraphicsGridLayout, andQGraphicsLinearLayout

Public Functions

QGraphicsLayout(QGraphicsLayoutItem * parent = 0)
~QGraphicsLayout()
voidactivate()
virtual intcount() const = 0
virtual voidinvalidate()
boolisActivated() const
virtual QGraphicsLayoutItem *itemAt(int i) const = 0
virtual voidremoveAt(int index) = 0
voidsetContentsMargins(qreal left, qreal top, qreal right, qreal bottom)
virtual voidwidgetEvent(QEvent * e)

Reimplemented Public Functions

virtual voidgetContentsMargins(qreal * left, qreal * top, qreal * right, qreal * bottom) const
virtual voidupdateGeometry()

Static Public Members

Protected Functions

voidaddChildLayoutItem(QGraphicsLayoutItem * layoutItem)

Detailed Description

TheQGraphicsLayout class provides the base class for all layouts in Graphics View.

QGraphicsLayout is an abstract class that defines a virtual API for arrangingQGraphicsWidget children and otherQGraphicsLayoutItem objects for aQGraphicsWidget.QGraphicsWidget assigns responsibility to aQGraphicsLayout throughQGraphicsWidget::setLayout(). As the widget is resized, the layout will automatically arrange the widget's children.QGraphicsLayout inheritsQGraphicsLayoutItem, so, it can be managed by any layout, including its own subclasses.

Writing a Custom Layout

You can useQGraphicsLayout as a base to write your own custom layout (e.g., a flowlayout), but it is more common to use one of its subclasses instead -QGraphicsLinearLayout orQGraphicsGridLayout. When creating a custom layout, the following functions must be reimplemented as a bare minimum:

FunctionDescription
QGraphicsLayoutItem::setGeometry()Notifies you when the geometry of the layout is set. You can store the geometry in your own layout class in a reimplementation of this function.
QGraphicsLayoutItem::sizeHint()Returns the layout's size hints.
QGraphicsLayout::count()Returns the number of items in your layout.
QGraphicsLayout::itemAt()Returns a pointer to an item in your layout.
QGraphicsLayout::removeAt()Removes an item from your layout without destroying it.

For more details on how to implement each function, refer to the individual function documentation.

Each layout defines its own API for arranging widgets and layout items. For example, with a grid layout, you require a row and a column index with optional row and column spans, alignment, spacing, and more. A linear layout, however, requires a single row or column index to position its items. For a grid layout, the order of insertion does not affect the layout in any way, but for a linear layout, the order is essential. When writing your own layout subclass, you are free to choose the API that best suits your layout.

For adding layout items to the custom layout, theQGraphicsLayout provides convenience functionaddChildLayoutItem(). The function will take care of automatically reparenting graphics items, if needed.

Activating the Layout

When the layout's geometry changes,QGraphicsLayout immediately rearranges all of its managed items by callingsetGeometry() on each item. This rearrangement is calledactivating the layout.

QGraphicsLayout updates its own geometry to match thecontentsRect() of theQGraphicsLayoutItem it is managing. Thus, it will automatically rearrange all its items when the widget is resized.QGraphicsLayout caches the sizes of all its managed items to avoid callingsetGeometry() too often.

Note:AQGraphicsLayout will have the same geometry as thecontentsRect() of the widget (not the layout) it is assigned to.

Activating the Layout Implicitly

The layout can be activated implicitly using one of two ways: by callingactivate() or by callinginvalidate(). Callingactivate() activates the layout immediately. In contrast, callinginvalidate() is delayed, as it posts aLayoutRequest event to the managed widget. Due to event compression, theactivate() will only be called once after control has returned to the event loop. This is referred to asinvalidating the layout. Invalidating the layout also invalidates any cached information. Also, theinvalidate() function is a virtual function. So, you can invalidate your own cache in a subclass ofQGraphicsLayout by reimplementing this function.

Event Handling

QGraphicsLayout listens to events for the widget it manages through the virtualwidgetEvent() event handler. When the layout is assigned to a widget, all events delivered to the widget are first processed bywidgetEvent(). This allows the layout to be aware of any relevant state changes on the widget such as visibility changes or layout direction changes.

Margin Handling

The margins of aQGraphicsLayout can be modified by reimplementingsetContentsMargins() andgetContentsMargins().

Member Function Documentation

QGraphicsLayout::QGraphicsLayout(QGraphicsLayoutItem * parent = 0)

Contructs aQGraphicsLayout object.

parent is passed toQGraphicsLayoutItem's constructor and theQGraphicsLayoutItem'sisLayout argument is set totrue.

Ifparent is aQGraphicsWidget the layout will be installed on that widget. (Note that installing a layout will delete the old one installed.)

QGraphicsLayout::~QGraphicsLayout()

Destroys theQGraphicsLayout object.

void QGraphicsLayout::activate()

Activates the layout, causing all items in the layout to be immediately rearranged. This function is based on callingcount() anditemAt(), and then callingsetGeometry() on all items sequentially. When activated, the layout will adjust its geometry to its parent'scontentsRect(). The parent will then invalidate any layout of its own.

If called in sequence or recursively, e.g., by one of the arranged items in response to being resized, this function will do nothing.

Note that the layout is free to use geometry caching to optimize this process. To forcefully invalidate any such cache, you can callinvalidate() before calling activate().

See alsoinvalidate().

[protected]void QGraphicsLayout::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 closestQGraphicsWidget ancestor of the layout.

IflayoutItem is already in a different layout, it will be removed from that layout.

If custom layouts want special behaviour they can ignore to use this function, and implement their own behaviour.

This function was introduced in Qt 4.6.

See alsographicsItem().

[pure virtual]int QGraphicsLayout::count() const

This pure virtual function must be reimplemented in a subclass ofQGraphicsLayout to return the number of items in the layout.

The subclass is free to decide how to store the items.

See alsoitemAt() andremoveAt().

[virtual]void QGraphicsLayout::getContentsMargins(qreal * left,qreal * top,qreal * right,qreal * bottom) const

Reimplemented fromQGraphicsLayoutItem::getContentsMargins().

[static]bool QGraphicsLayout::instantInvalidatePropagation()

returns true if the complete widget/layout hierarchy is rearranged in one go.

This function was introduced in Qt 4.8.

See alsosetInstantInvalidatePropagation().

[virtual]void QGraphicsLayout::invalidate()

Clears any cached geometry and size hint information in the layout, and posts aLayoutRequest event to the managed parentQGraphicsLayoutItem.

See alsoactivate() andsetGeometry().

bool QGraphicsLayout::isActivated() const

Returns true if the layout is currently being activated; otherwise, returns false. If the layout is being activated, this means that it is currently in the process of rearranging its items (i.e., theactivate() function has been called, and has not yet returned).

See alsoactivate() andinvalidate().

[pure virtual]QGraphicsLayoutItem * QGraphicsLayout::itemAt(int i) const

This pure virtual function must be reimplemented in a subclass ofQGraphicsLayout to return a pointer to the item at indexi. The reimplementation can assume thati is valid (i.e., it respects the value ofcount()). Together withcount(), it is provided as a means of iterating over all items in a layout.

The subclass is free to decide how to store the items, and the visual arrangement does not have to be reflected through this function.

See alsocount() andremoveAt().

[pure virtual]void QGraphicsLayout::removeAt(int index)

This pure virtual function must be reimplemented in a subclass ofQGraphicsLayout to remove the item atindex. The reimplementation can assume thatindex is valid (i.e., it respects the value ofcount()).

The implementation must ensure that theparentLayoutItem() of the removed item does not point to this layout, since the item is considered to be removed from the layout hierarchy.

If the layout is to be reused between applications, we recommend that the layout deletes the item, but the graphics view framework does not depend on this.

The subclass is free to decide how to store the items.

See alsoitemAt() andcount().

void QGraphicsLayout::setContentsMargins(qreal left,qreal top,qreal right,qreal bottom)

Sets the contents margins toleft,top,right andbottom. The default contents margins for toplevel layouts are style dependent (by querying the pixelMetric forQStyle::PM_LayoutLeftMargin,QStyle::PM_LayoutTopMargin,QStyle::PM_LayoutRightMargin andQStyle::PM_LayoutBottomMargin).

For sublayouts the default margins are 0.

Changing the contents margins automatically invalidates the layout.

See alsoinvalidate().

[static]void QGraphicsLayout::setInstantInvalidatePropagation(bool enable)

Calling this function withenable set to true will enable a feature that makes propagation of invalidation up to ancestor layout items to be done in one go. It will propagate up theparentLayoutItem() hierarchy until it has reached the root. If the root item is aQGraphicsWidget, it will *post* a layout request to it. When the layout request is consumed it will traverse down the hierarchy of layouts and widgets and activate all layouts that is invalid (not activated). This is the recommended behaviour.

If not set it will also propagate up theparentLayoutItem() hierarchy, but it will stop at thefirst widget it encounters, and post a layout request to the widget. When the layout request is consumed, this might cause it to continue propagation up to theparentLayoutItem() of the widget. It will continue in this fashion until it has reached a widget with noparentLayoutItem(). This strategy might cause drawing artifacts, since it is not done in one go, and the consumption of layout requests might be interleaved by consumption of paint events, which might cause significant flicker. Note, this is not the recommended behavior, but for compatibility reasons this is the default behaviour.

This function was introduced in Qt 4.8.

See alsoinstantInvalidatePropagation().

[virtual]void QGraphicsLayout::updateGeometry()

Reimplemented fromQGraphicsLayoutItem::updateGeometry().

[virtual]void QGraphicsLayout::widgetEvent(QEvent * e)

This virtual event handler receives all events for the managed widget.QGraphicsLayout uses this event handler to listen for layout related events such as geometry changes, layout changes or layout direction changes.

e is a pointer to the event.

You can reimplement this event handler to track similar events for your own custom layout.

See alsoQGraphicsWidget::event() andQGraphicsItem::sceneEvent().

© 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