PySide6.QtWidgets.QGraphicsLayoutItem¶
- class QGraphicsLayoutItem¶
- The - QGraphicsLayoutItemclass can be inherited to allow your custom items to be managed by layouts. More…- Inherited by: - QGraphicsLayout,- QGraphicsLinearLayout,- QGraphicsGridLayout,- QGraphicsAnchorLayout,- QGraphicsWidget,- QGraphicsProxyWidget,- QLegend,- QChart,- QPolarChart- Synopsis¶- Methods¶- def - __init__()
- def - contentsRect()
- def - geometry()
- def - graphicsItem()
- def - isLayout()
- def - maximumHeight()
- def - maximumSize()
- def - maximumWidth()
- def - minimumHeight()
- def - minimumSize()
- def - minimumWidth()
- def - ownedByLayout()
- def - preferredSize()
- def - preferredWidth()
- def - setMaximumSize()
- def - setMinimumSize()
- def - setSizePolicy()
- def - sizePolicy()
 - Virtual methods¶
- def - isEmpty()
- def - setGeometry()
- def - sizeHint()
- def - updateGeometry()
 - Note - This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE - Detailed Description¶- QGraphicsLayoutItemis 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 - QGraphicsWidgetand- QGraphicsLayoutalready 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).- Subclassing QGraphicsLayoutItem¶- If you create a subclass of - QGraphicsLayoutItemand reimplement its virtual functions, you will enable the layout to resize and position your item along with other QGraphicsLayoutItems including- QGraphicsWidgetand- QGraphicsLayout.- You can start by reimplementing important functions: the protected - sizeHint()function, as well as the public- setGeometry()function. If you want your items to be aware of immediate geometry changes, you can also reimplement- updateGeometry().- The geometry, size hint, and size policy affect the item’s size and position. Calling - setGeometry()will always resize and reposition the item immediately. Normally, this function is called by- QGraphicsLayoutafter the layout has been activated, but it can also be called by the item’s user at any time.- The - sizeHint()function returns the item’ minimum, preferred and maximum size hints. You can override these properties by calling- setMinimumSize(),- setPreferredSize()or- setMaximumSize(). You can also use functions such as- setMinimumWidth()or- setMaximumHeight()to set only the width or height component if desired.- The - 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- setSizePolicy(). The- sizePolicyproperty 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 - QGraphicsLayoutItempointer to- QGraphicsLayoutItem‘s protected constructor, or by calling- setParentLayoutItem(). The- parentLayoutItem()function returns a pointer to the item’s layoutItem parent. If the item’s parent is- Noneor if the parent does not inherit from- QGraphicsItem, the- parentLayoutItem()function then returns- None.- isLayout()returns- trueif the- QGraphicsLayoutItemsubclass is itself a layout, or false otherwise.- Qt uses - QGraphicsLayoutItemto provide layout functionality in the Graphics View Framework , but in the future its use may spread throughout Qt itself.- __init__([parent=None[, isLayout=false]])¶
- Parameters:
- parent – - QGraphicsLayoutItem
- isLayout – bool 
 
 
 - Constructs the - QGraphicsLayoutItemobject.- parentbecomes the object’s parent. If- isLayoutis true the item is a layout, otherwise- isLayoutis false.- 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.- See also - effectiveSizeHint(which[, constraint=QSizeF()])¶
 - Returns the effective size hint for this - QGraphicsLayoutItem.- whichis the size hint in question.- constraintis an optional argument that defines a special constrain when calculating the effective size hint. By default,- constraintis 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- QGraphicsLayoutItemsubclass, 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- constraintis not specified and- updateGeometry()has been called.- See also - Returns the item’s geometry (e.g., position and size) as a QRectF. This function is equivalent to QRectF(pos(), size()). - See also - getContentsMargins()¶
- Return type:
- PyObject 
 
 - This virtual function provides the - left,- top,- rightand- bottomcontents 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- None, that value will not be updated.- See also - graphicsItem()¶
- Return type:
 
 - Returns the - QGraphicsItemthat this layout item represents. For- QGraphicsWidgetit will return itself. For custom items it can return an aggregated value.- See also - isEmpty()¶
- Return type:
- bool 
 
 - Returns - trueif this item is empty, i.e whether it has no content and should not occupy any space.- The default implementation returns - truetrue if the item has been hidden, unless its- size policyhas retainSizeWhenHidden set to- true- See also - isLayout()¶
- Return type:
- bool 
 
 - Returns - trueif this- QGraphicsLayoutItemis a layout (e.g., is inherited by an object that arranges other- QGraphicsLayoutItemobjects); otherwise returns- false.- See also - maximumHeight()¶
- Return type:
- float 
 
 - Returns the maximum height. - Returns the maximum size. - maximumWidth()¶
- Return type:
- float 
 
 - Returns the maximum width. - minimumHeight()¶
- Return type:
- float 
 
 - Returns the minimum height. - Returns the minimum size. - minimumWidth()¶
- Return type:
- float 
 
 - Returns the minimum width. - ownedByLayout()¶
- Return type:
- 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 - QGraphicsItemand- QGraphicsLayoutItem(such as- QGraphicsWidgetdoes) 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- QGraphicsLayoutto return true. This is because- QGraphicsLayoutis not normally part of the- QGraphicsItemhierarchy, so the parent layout should delete it. Subclasses might override this default behaviour by calling- setOwnedByLayout(true).- See also - parentLayoutItem()¶
- Return type:
 
 - Returns the parent of this - QGraphicsLayoutItem, or- Noneif there is no parent, or if the parent does not inherit from- QGraphicsLayoutItem(- QGraphicsLayoutItemis often used through multiple inheritance with QObject-derived classes).- See also - preferredHeight()¶
- Return type:
- float 
 
 - Returns the preferred height. - Returns the preferred size. - preferredWidth()¶
- Return type:
- float 
 
 - Returns the preferred width. - This virtual function sets the geometry of the - QGraphicsLayoutItemto- rect, which is in parent coordinates (e.g., the top-left corner of- rectis equivalent to the item’s position in parent coordinates).- You must reimplement this function in a subclass of - QGraphicsLayoutItemto receive geometry updates. The layout will call this function when it does a rearrangement.- If - rectis outside of the bounds of- minimumSizeand- maximumSize, it will be adjusted to its closest size so that it is within the legal bounds.- See also - setGraphicsItem(item)¶
- Parameters:
- item – - QGraphicsItem
 
 - If the - QGraphicsLayoutItemrepresents a- QGraphicsItem, and it wants to take advantage of the automatic reparenting capabilities of- QGraphicsLayoutit should set this value. Note that if you delete- itemand not delete the layout item, you are responsible of calling setGraphicsItem(- None) in order to avoid having a dangling pointer.- See also - setMaximumHeight(height)¶
- Parameters:
- height – float 
 
 - Sets the maximum height to - height.- See also - 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.- setMaximumSize(w, h)
- Parameters:
- w – float 
- h – float 
 
 
 - This convenience function is equivalent to calling - setMaximumSize(QSizeF(- w,- h)).- setMaximumWidth(width)¶
- Parameters:
- width – float 
 
 - Sets the maximum width to - width.- See also - setMinimumHeight(height)¶
- Parameters:
- height – float 
 
 - Sets the minimum height to - height.- See also - 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.- setMinimumSize(w, h)
- Parameters:
- w – float 
- h – float 
 
 
 - This convenience function is equivalent to calling - setMinimumSize(QSizeF(- w,- h)).- setMinimumWidth(width)¶
- Parameters:
- width – float 
 
 - Sets the minimum width to - width.- See also - setOwnedByLayout(ownedByLayout)¶
- Parameters:
- ownedByLayout – bool 
 
 - Sets whether a layout should delete this item in its destructor or not. - ownershipmust be true to in order for the layout to delete it.- See also - setParentLayoutItem(parent)¶
- Parameters:
- parent – - QGraphicsLayoutItem
 
 - Sets the parent of this - QGraphicsLayoutItemto- parent.- See also - setPreferredHeight(height)¶
- Parameters:
- height – float 
 
 - Sets the preferred height to - height.- 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.- setPreferredSize(w, h)
- Parameters:
- w – float 
- h – float 
 
 
 - This convenience function is equivalent to calling - setPreferredSize(QSizeF(- w,- h)).- setPreferredWidth(width)¶
- Parameters:
- width – float 
 
 - Sets the preferred width to - width.- setSizePolicy(policy)¶
- Parameters:
- policy – - QSizePolicy
 
 - 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 (- Fixed,- Fixed,- DefaultType), but it is common for subclasses to change the default. For example,- QGraphicsWidgetdefaults to (- Preferred,- Preferred,- DefaultType).- See also - setSizePolicy(hPolicy, vPolicy[, controlType=QSizePolicy.DefaultType])
- Parameters:
- hPolicy – - Policy
- vPolicy – - Policy
- controlType – - ControlType
 
 
 - This is an overloaded function. - This function is equivalent to calling - setSizePolicy(- QSizePolicy(- hPolicy,- vPolicy,- controlType)).- See also - abstract sizeHint(which[, constraint=QSizeF()])¶
 - This pure virtual function returns the size hint for - whichof the- QGraphicsLayoutItem, using the width or height of- constraintto constrain the output.- Reimplement this function in a subclass of - QGraphicsLayoutItemto provide the necessary size hints for your items.- See also - sizePolicy()¶
- Return type:
 
 - Returns the current size policy. - See also - updateGeometry()¶
 - 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.- See also