QtBase
v6.3.1
|
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts. More...
#include <qgraphicslayoutitem.h>
Protected Member Functions | |
void | setGraphicsItem (QGraphicsItem *item) |
void | setOwnedByLayout (bool ownedByLayout) |
QGraphicsLayoutItem (QGraphicsLayoutItemPrivate &dd) | |
virtual QSizeF | sizeHint (Qt::SizeHint which, const QSizeF &constraint=QSizeF()) const =0 |
Protected Attributes | |
QScopedPointer< QGraphicsLayoutItemPrivate > | d_ptr |
Friends | |
class | QGraphicsLayout |
The QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.
\inmodule QtWidgets
QGraphicsLayoutItem is an abstract class that defines a set of virtual functions describing sizes, size policies, and size hints for any object arranged by QGraphicsLayout. The API contains functions relevant for both the item itself and for the user of the item as most of QGraphicsLayoutItem's functions are also part of the subclass' public API.
In most cases, existing layout-aware classes such as QGraphicsWidget and QGraphicsLayout already provide the functionality you require. However, subclassing these classes will enable you to create both graphical elements that work well with layouts (QGraphicsWidget) or custom layouts (QGraphicsLayout).
Definition at line 54 of file qgraphicslayoutitem.h.
QGraphicsLayoutItem::QGraphicsLayoutItem | ( | QGraphicsLayoutItem * | parent = nullptr , |
bool | isLayout = false |
||
) |
Constructs the QGraphicsLayoutItem object. parent becomes the object's parent. If isLayout is true the item is a layout, otherwise isLayout is false.
Definition at line 390 of file qgraphicslayoutitem.cpp.
|
virtual |
Destroys the QGraphicsLayoutItem object.
Definition at line 413 of file qgraphicslayoutitem.cpp.
|
protected |
Definition at line 402 of file qgraphicslayoutitem.cpp.
QRectF QGraphicsLayoutItem::contentsRect | ( | ) | const |
Returns the contents rect in local coordinates.
The contents rect defines the subrectangle used by an associated layout when arranging subitems. This function is a convenience function that adjusts the item's geometry() by its contents margins. Note that getContentsMargins() is a virtual function that you can reimplement to return the item's contents margins.
Definition at line 768 of file qgraphicslayoutitem.cpp.
QSizeF QGraphicsLayoutItem::effectiveSizeHint | ( | Qt::SizeHint | which, |
const QSizeF & | constraint = QSizeF() |
||
) | const |
Returns the effective size hint for this QGraphicsLayoutItem.
which is the size hint in question. constraint is an optional argument that defines a special constrain when calculating the effective size hint. By default, constraint is QSizeF(-1, -1), which means there is no constraint to the size hint.
If you want to specify the widget's size hint for a given width or height, you can provide the fixed dimension in constraint. This is useful for widgets that can grow only either vertically or horizontally, and need to set either their width or their height to a special value.
For example, a text paragraph item fit into a column width of 200 may grow vertically. You can pass QSizeF(200, -1) as a constraint to get a suitable minimum, preferred and maximum height).
You can adjust the effective size hint by reimplementing sizeHint() in a QGraphicsLayoutItem subclass, or by calling one of the following functions: setMinimumSize(), setPreferredSize, or setMaximumSize() (or a combination of both).
This function caches each of the size hints and guarantees that sizeHint() will be called only once for each value of which - unless constraint is not specified and updateGeometry() has been called.
Definition at line 803 of file qgraphicslayoutitem.cpp.
QRectF QGraphicsLayoutItem::geometry | ( | ) | const |
Returns the item's geometry (e.g., position and size) as a QRectF. This function is equivalent to QRectF(pos(), size()).
Definition at line 731 of file qgraphicslayoutitem.cpp.
|
virtual |
This virtual function provides the left, top, right and bottom contents margins for this QGraphicsLayoutItem. The default implementation assumes all contents margins are 0. The parameters point to values stored in qreals. If any of the pointers is \nullptr, that value will not be updated.
Reimplemented in QGraphicsWidget, and QGraphicsLayout.
Definition at line 745 of file qgraphicslayoutitem.cpp.
QGraphicsItem * QGraphicsLayoutItem::graphicsItem | ( | ) | const |
Returns the QGraphicsItem that this layout item represents. For QGraphicsWidget it will return itself. For custom items it can return an aggregated value.
Definition at line 931 of file qgraphicslayoutitem.cpp.
|
virtual |
Returns true
if this item is empty, i.e whether it has no content and should not occupy any space.
The default implementation returns true
true if the item has been hidden, unless its \l{sizePolicy()}{size policy} has retainSizeWhenHidden set to true
Reimplemented in LayoutItem.
Definition at line 840 of file qgraphicslayoutitem.cpp.
bool QGraphicsLayoutItem::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
.
Definition at line 879 of file qgraphicslayoutitem.cpp.
|
inline |
Returns the maximum height.
Definition at line 143 of file qgraphicslayoutitem.h.
QSizeF QGraphicsLayoutItem::maximumSize | ( | ) | const |
Returns the maximum size.
Definition at line 625 of file qgraphicslayoutitem.cpp.
|
inline |
Returns the maximum width.
Definition at line 141 of file qgraphicslayoutitem.h.
|
inline |
Returns the minimum height.
Definition at line 133 of file qgraphicslayoutitem.h.
QSizeF QGraphicsLayoutItem::minimumSize | ( | ) | const |
Returns the minimum size.
Definition at line 517 of file qgraphicslayoutitem.cpp.
|
inline |
Returns the minimum width.
Definition at line 131 of file qgraphicslayoutitem.h.
bool QGraphicsLayoutItem::ownedByLayout | ( | ) | const |
Returns whether a layout should delete this item in its destructor. If its true, then the layout will delete it. If its false, then it is assumed that another object has the ownership of it, and the layout won't delete this item.
If the item inherits both QGraphicsItem and QGraphicsLayoutItem (such as QGraphicsWidget does) the item is really part of two ownership hierarchies. This property informs what the layout should do with its child items when it is destructed. In the case of QGraphicsWidget, it is preferred that when the layout is deleted it won't delete its children (since they are also part of the graphics item hierarchy).
By default this value is initialized to false in QGraphicsLayoutItem, but it is overridden by QGraphicsLayout to return true. This is because QGraphicsLayout is not normally part of the QGraphicsItem hierarchy, so the parent layout should delete it. Subclasses might override this default behaviour by calling setOwnedByLayout(true).
Definition at line 908 of file qgraphicslayoutitem.cpp.
QGraphicsLayoutItem * QGraphicsLayoutItem::parentLayoutItem | ( | ) | const |
Returns the parent of this QGraphicsLayoutItem, or \nullptr 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).
Definition at line 857 of file qgraphicslayoutitem.cpp.
|
inline |
Returns the preferred height.
Definition at line 138 of file qgraphicslayoutitem.h.
QSizeF QGraphicsLayoutItem::preferredSize | ( | ) | const |
Returns the preferred size.
Definition at line 571 of file qgraphicslayoutitem.cpp.
|
inline |
Returns the preferred width.
Definition at line 136 of file qgraphicslayoutitem.h.
This virtual function sets the geometry of the QGraphicsLayoutItem to rect, which is in parent coordinates (e.g., the top-left corner of rect is equivalent to the item's position in parent coordinates).
You must reimplement this function in a subclass of QGraphicsLayoutItem to receive geometry updates. The layout will call this function when it does a rearrangement.
If rect is outside of the bounds of minimumSize and maximumSize, it will be adjusted to its closest size so that it is within the legal bounds.
Reimplemented in SubQGraphicsLayoutItem, RectWidget, Layout, TestLayout, TestGraphicsWidget, QGraphicsWidget, QGraphicsProxyWidget, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsAnchorLayout, PixmapWidget, SlowWidget, AnimatedLayout, AnimatedLayoutItem, FlowLayout, and LayoutItem.
Definition at line 715 of file qgraphicslayoutitem.cpp.
|
protected |
If the QGraphicsLayoutItem represents a QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of QGraphicsLayout it should set this value. Note that if you delete item and not delete the layout item, you are responsible of calling setGraphicsItem(\nullptr) in order to avoid having a dangling pointer.
Definition at line 946 of file qgraphicslayoutitem.cpp.
Sets the maximum height to height.
Definition at line 645 of file qgraphicslayoutitem.cpp.
Sets the maximum size to size. This property overrides sizeHint() for Qt::MaximumSize and ensures that effectiveSizeHint() will never return a size larger than size. In order to unset the maximum size, use an invalid size.
Definition at line 605 of file qgraphicslayoutitem.cpp.
This convenience function is equivalent to calling setMaximumSize(QSizeF(w, h)).
Definition at line 128 of file qgraphicslayoutitem.h.
Sets the maximum width to width.
Definition at line 635 of file qgraphicslayoutitem.cpp.
Sets the minimum height to height.
Definition at line 537 of file qgraphicslayoutitem.cpp.
Sets the minimum size to size. This property overrides sizeHint() for Qt::MinimumSize and ensures that effectiveSizeHint() will never return a size smaller than size. In order to unset the minimum size, use an invalid size.
Definition at line 497 of file qgraphicslayoutitem.cpp.
This convenience function is equivalent to calling setMinimumSize(QSizeF(w, h)).
Definition at line 124 of file qgraphicslayoutitem.h.
Sets the minimum width to width.
Definition at line 527 of file qgraphicslayoutitem.cpp.
|
protected |
Sets whether a layout should delete this item in its destructor or not. ownership must be true to in order for the layout to delete it.
Definition at line 919 of file qgraphicslayoutitem.cpp.
void QGraphicsLayoutItem::setParentLayoutItem | ( | QGraphicsLayoutItem * | parent | ) |
Sets the parent of this QGraphicsLayoutItem to parent.
Definition at line 867 of file qgraphicslayoutitem.cpp.
Sets the preferred height to height.
Definition at line 581 of file qgraphicslayoutitem.cpp.
Sets the preferred size to size. This property overrides sizeHint() for Qt::PreferredSize and provides the default value for effectiveSizeHint(). In order to unset the preferred size, use an invalid size.
Definition at line 551 of file qgraphicslayoutitem.cpp.
This convenience function is equivalent to calling setPreferredSize(QSizeF(w, h)).
Definition at line 126 of file qgraphicslayoutitem.h.
Sets the preferred width to width.
Definition at line 591 of file qgraphicslayoutitem.cpp.
void QGraphicsLayoutItem::setSizePolicy | ( | const QSizePolicy & | policy | ) |
Sets the size policy to policy. The size policy describes how the item should grow horizontally and vertically when arranged in a layout.
QGraphicsLayoutItem's default size policy is (QSizePolicy::Fixed, QSizePolicy::Fixed, QSizePolicy::DefaultType), but it is common for subclasses to change the default. For example, QGraphicsWidget defaults to (QSizePolicy::Preferred, QSizePolicy::Preferred, QSizePolicy::DefaultType).
Definition at line 453 of file qgraphicslayoutitem.cpp.
void QGraphicsLayoutItem::setSizePolicy | ( | QSizePolicy::Policy | hPolicy, |
QSizePolicy::Policy | vPolicy, | ||
QSizePolicy::ControlType | controlType = QSizePolicy::DefaultType |
||
) |
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This function is equivalent to calling setSizePolicy(QSizePolicy(hPolicy, vPolicy, controlType)).
Definition at line 470 of file qgraphicslayoutitem.cpp.
|
protectedpure virtual |
This pure virtual function returns the size hint for which of the QGraphicsLayoutItem, using the width or height of constraint to constrain the output.
Reimplement this function in a subclass of QGraphicsLayoutItem to provide the necessary size hints for your items.
Implemented in SubQGraphicsLayoutItem, CustomLayout, MySquareWidget, HFWWidget, SizeHinter, RectWidget, CustomGraphicsWidget, CustomLayoutItem, AnimatedLayoutItem, Layout, RectWidget, TestWidget, QGraphicsWidget, QGraphicsProxyWidget, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsAnchorLayout, PixmapWidget, FlowLayout, LayoutItem, and SimpleListView.
QSizePolicy QGraphicsLayoutItem::sizePolicy | ( | ) | const |
Returns the current size policy.
Definition at line 482 of file qgraphicslayoutitem.cpp.
|
virtual |
This virtual function discards any cached size hint information. You should always call this function if you change the return value of the sizeHint() function. Subclasses must always call the base implementation when reimplementing this function.
Reimplemented in SubQGraphicsLayoutItem, QGraphicsWidget, and QGraphicsLayout.
Definition at line 822 of file qgraphicslayoutitem.cpp.
|
friend |
Definition at line 117 of file qgraphicslayoutitem.h.
|
protected |
Definition at line 111 of file qgraphicslayoutitem.h.