Inherited by: QGraphicsLayout, QGraphicsLinearLayout, QGraphicsGridLayout, QGraphicsAnchorLayout, QGraphicsWidget, QGraphicsProxyWidget, QGraphicsWebView



Virtual functions

Detailed Description

The PySide.QtGui.QGraphicsLayoutItem class can be inherited to allow your custom items to be managed by layouts.

PySide.QtGui.QGraphicsLayoutItem is an abstract class that defines a set of virtual functions describing sizes, size policies, and size hints for any object arranged by PySide.QtGui.QGraphicsLayout . The API contains functions relevant for both the item itself and for the user of the item as most of PySide.QtGui.QGraphicsLayoutItem ‘s functions are also part of the subclass’ public API.

In most cases, existing layout-aware classes such as PySide.QtGui.QGraphicsWidget and PySide.QtGui.QGraphicsLayout already provide the functionality you require. However, subclassing these classes will enable you to create both graphical elements that work well with layouts ( PySide.QtGui.QGraphicsWidget ) or custom layouts ( PySide.QtGui.QGraphicsLayout ).

Subclassing QGraphicsLayoutItem

If you create a subclass of PySide.QtGui.QGraphicsLayoutItem and reimplement its virtual functions, you will enable the layout to resize and position your item along with other QGraphicsLayoutItems including PySide.QtGui.QGraphicsWidget and PySide.QtGui.QGraphicsLayout .

You can start by reimplementing important functions: the protected PySide.QtGui.QGraphicsLayoutItem.sizeHint() function, as well as the public PySide.QtGui.QGraphicsLayoutItem.setGeometry() function. If you want your items to be aware of immediate geometry changes, you can also reimplement PySide.QtGui.QGraphicsLayoutItem.updateGeometry() .

The geometry, size hint, and size policy affect the item’s size and position. Calling PySide.QtGui.QGraphicsLayoutItem.setGeometry() will always resize and reposition the item immediately. Normally, this function is called by PySide.QtGui.QGraphicsLayout after the layout has been activated, but it can also be called by the item’s user at any time.

The PySide.QtGui.QGraphicsLayoutItem.sizeHint() function returns the item’ minimum, preferred and maximum size hints. You can override these properties by calling PySide.QtGui.QGraphicsLayoutItem.setMinimumSize() , PySide.QtGui.QGraphicsLayoutItem.setPreferredSize() or PySide.QtGui.QGraphicsLayoutItem.setMaximumSize() . You can also use functions such as PySide.QtGui.QGraphicsLayoutItem.setMinimumWidth() or PySide.QtGui.QGraphicsLayoutItem.setMaximumHeight() to set only the width or height component if desired.

The PySide.QtGui.QGraphicsLayoutItem.effectiveSizeHint() function, on the other hand, returns a size hint for any given Qt.SizeHint , and guarantees that the returned size is bound to the minimum and maximum sizes and size hints. You can set the item’s vertical and horizontal size policy by calling PySide.QtGui.QGraphicsLayoutItem.setSizePolicy() . The sizePolicy property is used by the layout system to describe how this item prefers to grow or shrink.

Nesting QGraphicsLayoutItems

QGraphicsLayoutItems can be nested within other QGraphicsLayoutItems, similar to layouts that can contain sublayouts. This is done either by passing a PySide.QtGui.QGraphicsLayoutItem pointer to PySide.QtGui.QGraphicsLayoutItem ‘s protected constructor, or by calling PySide.QtGui.QGraphicsLayoutItem.setParentLayoutItem() . The PySide.QtGui.QGraphicsLayoutItem.parentLayoutItem() function returns a pointer to the item’s layoutItem parent. If the item’s parent is 0 or if the parent does not inherit from PySide.QtGui.QGraphicsItem , the PySide.QtGui.QGraphicsLayoutItem.parentLayoutItem() function then returns 0. PySide.QtGui.QGraphicsLayoutItem.isLayout() returns true if the PySide.QtGui.QGraphicsLayoutItem subclass is itself a layout, or false otherwise.

Qt uses PySide.QtGui.QGraphicsLayoutItem to provide layout functionality in the Graphics View Framework , but in the future its use may spread throughout Qt itself.

class PySide.QtGui.QGraphicsLayoutItem([parent=None[, isLayout=false]])

Constructs the PySide.QtGui.QGraphicsLayoutItem object. parent becomes the object’s parent. If isLayout is true the item is a layout, otherwise isLayout is false.

Return type:PySide.QtCore.QRectF

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 PySide.QtGui.QGraphicsLayoutItem.geometry() by its contents margins. Note that PySide.QtGui.QGraphicsLayoutItem.getContentsMargins() is a virtual function that you can reimplement to return the item’s contents margins.

PySide.QtGui.QGraphicsLayoutItem.effectiveSizeHint(which[, constraint=QSizeF()])
Return type:


Return type:PySide.QtCore.QSizeF
Return type:PySide.QtCore.QRectF

Returns the item’s geometry (e.g., position and size) as a PySide.QtCore.QRectF . This function is equivalent to PySide.QtCore.QRectF (pos(), size() ).


This virtual function provides the left , top , right and bottom contents margins for this PySide.QtGui.QGraphicsLayoutItem . The default implementation assumes all contents margins are 0. The parameters point to values stored in qreals. If any of the pointers is 0, that value will not be updated.

Return type:PySide.QtGui.QGraphicsItem

Returns the PySide.QtGui.QGraphicsItem that this layout item represents. For PySide.QtGui.QGraphicsWidget it will return itself. For custom items it can return an aggregated value.

Return type:PySide.QtCore.bool

Returns true if this PySide.QtGui.QGraphicsLayoutItem is a layout (e.g., is inherited by an object that arranges other PySide.QtGui.QGraphicsLayoutItem objects); otherwise returns false.

Return type:PySide.QtCore.qreal

Returns the maximum height.

Return type:PySide.QtCore.QSizeF

Returns the maximum size.

Return type:PySide.QtCore.qreal

Returns the maximum width.

Return type:PySide.QtCore.qreal

Returns the minimum height.

Return type:PySide.QtCore.QSizeF

Returns the minimum size.

Return type:PySide.QtCore.qreal

Returns the minimum width.

Return type:PySide.QtCore.bool

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 PySide.QtGui.QGraphicsItem and PySide.QtGui.QGraphicsLayoutItem (such as PySide.QtGui.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 PySide.QtGui.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 PySide.QtGui.QGraphicsLayoutItem , but it is overridden by PySide.QtGui.QGraphicsLayout to return true. This is because PySide.QtGui.QGraphicsLayout is not normally part of the PySide.QtGui.QGraphicsItem hierarchy, so the parent layout should delete it. Subclasses might override this default behaviour by calling setOwnedByLayout(true).

Return type:PySide.QtGui.QGraphicsLayoutItem

Returns the parent of this PySide.QtGui.QGraphicsLayoutItem , or 0 if there is no parent, or if the parent does not inherit from PySide.QtGui.QGraphicsLayoutItem ( PySide.QtGui.QGraphicsLayoutItem is often used through multiple inheritance with PySide.QtCore.QObject -derived classes).

Return type:PySide.QtCore.qreal

Returns the preferred height.

Return type:PySide.QtCore.QSizeF

Returns the preferred size.

Return type:PySide.QtCore.qreal

Returns the preferred width.


This virtual function sets the geometry of the PySide.QtGui.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 PySide.QtGui.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.


If the PySide.QtGui.QGraphicsLayoutItem represents a PySide.QtGui.QGraphicsItem , and it wants to take advantage of the automatic reparenting capabilities of PySide.QtGui.QGraphicsLayout it should set this value. Note that if you delete item and not delete the layout item, you are responsible of calling setGraphicsItem(0) in order to avoid having a dangling pointer.


Sets the maximum height to height .

PySide.QtGui.QGraphicsLayoutItem.setMaximumSize(w, h)
  • wPySide.QtCore.qreal
  • hPySide.QtCore.qreal

This convenience function is equivalent to calling setMaximumSize( PySide.QtCore.QSizeF (w , h )).


Sets the maximum size to size . This property overrides PySide.QtGui.QGraphicsLayoutItem.sizeHint() for Qt.MaximumSize and ensures that PySide.QtGui.QGraphicsLayoutItem.effectiveSizeHint() will never return a size larger than size . In order to unset the maximum size, use an invalid size.


Sets the maximum width to width .


Sets the minimum height to height .


Sets the minimum size to size . This property overrides PySide.QtGui.QGraphicsLayoutItem.sizeHint() for Qt.MinimumSize and ensures that PySide.QtGui.QGraphicsLayoutItem.effectiveSizeHint() will never return a size smaller than size . In order to unset the minimum size, use an invalid size.

PySide.QtGui.QGraphicsLayoutItem.setMinimumSize(w, h)
  • wPySide.QtCore.qreal
  • hPySide.QtCore.qreal

This convenience function is equivalent to calling setMinimumSize( PySide.QtCore.QSizeF (w , h )).


Sets the minimum width to width .


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.


Sets the parent of this PySide.QtGui.QGraphicsLayoutItem to parent .


Sets the preferred height to height .

PySide.QtGui.QGraphicsLayoutItem.setPreferredSize(w, h)
  • wPySide.QtCore.qreal
  • hPySide.QtCore.qreal

This convenience function is equivalent to calling setPreferredSize( PySide.QtCore.QSizeF (w , h )).


Sets the preferred size to size . This property overrides PySide.QtGui.QGraphicsLayoutItem.sizeHint() for Qt.PreferredSize and provides the default value for PySide.QtGui.QGraphicsLayoutItem.effectiveSizeHint() . In order to unset the preferred size, use an invalid size.


Sets the preferred width to width .


Sets the size policy to policy . The size policy describes how the item should grow horizontally and vertically when arranged in a layout.

PySide.QtGui.QGraphicsLayoutItem ‘s default size policy is ( QSizePolicy.Fixed , QSizePolicy.Fixed , QSizePolicy.DefaultType ), but it is common for subclasses to change the default. For example, PySide.QtGui.QGraphicsWidget defaults to ( QSizePolicy.Preferred , QSizePolicy.Preferred , QSizePolicy.DefaultType ).

PySide.QtGui.QGraphicsLayoutItem.setSizePolicy(hPolicy, vPolicy[, controlType=QSizePolicy.DefaultType])
PySide.QtGui.QGraphicsLayoutItem.sizeHint(which[, constraint=QSizeF()])
Return type:


Return type:PySide.QtGui.QSizePolicy

Returns the current size policy.


This virtual function discards any cached size hint information. You should always call this function if you change the return value of the PySide.QtGui.QGraphicsLayoutItem.sizeHint() function. Subclasses must always call the base implementation when reimplementing this function.