QGraphicsLayoutItem¶
The
QGraphicsLayoutItem
class can be inherited to allow your custom items to be managed by layouts. More…
Inherited by: QGraphicsAnchorLayout, QGraphicsGridLayout, QGraphicsLayout, QGraphicsLinearLayout
Synopsis¶
Functions¶
def
contentsRect
()def
effectiveSizeHint
(which[, constraint=QSizeF()])def
geometry
()def
graphicsItem
()def
isLayout
()def
maximumHeight
()def
maximumSize
()def
maximumWidth
()def
minimumHeight
()def
minimumSize
()def
minimumWidth
()def
ownedByLayout
()def
parentLayoutItem
()def
preferredHeight
()def
preferredSize
()def
preferredWidth
()def
setGraphicsItem
(item)def
setMaximumHeight
(height)def
setMaximumSize
(size)def
setMaximumSize
(w, h)def
setMaximumWidth
(width)def
setMinimumHeight
(height)def
setMinimumSize
(size)def
setMinimumSize
(w, h)def
setMinimumWidth
(width)def
setOwnedByLayout
(ownedByLayout)def
setParentLayoutItem
(parent)def
setPreferredHeight
(height)def
setPreferredSize
(size)def
setPreferredSize
(w, h)def
setPreferredWidth
(width)def
setSizePolicy
(hPolicy, vPolicy[, controlType=QSizePolicy.DefaultType])def
setSizePolicy
(policy)def
sizePolicy
()
Virtual functions¶
def
getContentsMargins
()def
setGeometry
(rect)def
sizeHint
(which[, constraint=QSizeF()])def
updateGeometry
()
Detailed Description¶
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 ofQGraphicsLayoutItem
‘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 ).
Subclassing QGraphicsLayoutItem¶
If you create a subclass of
QGraphicsLayoutItem
and reimplement its virtual functions, you will enable the layout to resize and position your item along with other QGraphicsLayoutItems including QGraphicsWidget and QGraphicsLayout .You can start by reimplementing important functions: the protected
sizeHint()
function, as well as the publicsetGeometry()
function. If you want your items to be aware of immediate geometry changes, you can also reimplementupdateGeometry()
.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 QGraphicsLayout after 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 callingsetMinimumSize()
,setPreferredSize()
orsetMaximumSize()
. You can also use functions such assetMinimumWidth()
orsetMaximumHeight()
to set only the width or height component if desired.The
effectiveSizeHint()
function, on the other hand, returns a size hint for any givenSizeHint
, 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 callingsetSizePolicy()
. ThesizePolicy
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
QGraphicsLayoutItem
pointer toQGraphicsLayoutItem
‘s protected constructor, or by callingsetParentLayoutItem()
. TheparentLayoutItem()
function returns a pointer to the item’s layoutItem parent. If the item’s parent isNone
or if the parent does not inherit fromQGraphicsItem
, theparentLayoutItem()
function then returnsNone
.isLayout()
returnstrue
if theQGraphicsLayoutItem
subclass is itself a layout, or false otherwise.Qt uses
QGraphicsLayoutItem
to provide layout functionality in the Graphics View Framework , but in the future its use may spread throughout Qt itself.
- class PySide2.QtWidgets.QGraphicsLayoutItem([parent=None[, isLayout=false]])¶
- param parent:
- param isLayout:
bool
Constructs the
QGraphicsLayoutItem
object.parent
becomes the object’s parent. IfisLayout
is true the item is a layout, otherwiseisLayout
is false.
- PySide2.QtWidgets.QGraphicsLayoutItem.contentsRect()¶
- Return type:
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 thatgetContentsMargins()
is a virtual function that you can reimplement to return the item’s contents margins.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.effectiveSizeHint(which[, constraint=QSizeF()])¶
- Parameters:
which –
SizeHint
constraint –
PySide2.QtCore.QSizeF
- Return type:
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
isQSizeF
(-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 aQGraphicsLayoutItem
subclass, or by calling one of the following functions:setMinimumSize()
,setPreferredSize
, orsetMaximumSize()
(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 ofwhich
- unlessconstraint
is not specified andupdateGeometry()
has been called.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.geometry()¶
- Return type:
Returns the item’s geometry (e.g., position and size) as a
QRectF
. This function is equivalent toQRectF
(pos(), size()).See also
- PySide2.QtWidgets.QGraphicsLayoutItem.getContentsMargins()¶
This virtual function provides the
left
,top
,right
andbottom
contents margins for thisQGraphicsLayoutItem
. The default implementation assumes all contents margins are 0. The parameters point to values stored in qreals. If any of the pointers isNone
, that value will not be updated.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.graphicsItem()¶
- Return type:
Returns the
QGraphicsItem
that this layout item represents. For QGraphicsWidget it will return itself. For custom items it can return an aggregated value.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.isLayout()¶
- Return type:
bool
Returns
true
if thisQGraphicsLayoutItem
is a layout (e.g., is inherited by an object that arranges otherQGraphicsLayoutItem
objects); otherwise returnsfalse
.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.maximumHeight()¶
- Return type:
float
Returns the maximum height.
- PySide2.QtWidgets.QGraphicsLayoutItem.maximumSize()¶
- Return type:
Returns the maximum size.
See also
setMaximumSize()
minimumSize()
preferredSize()
MaximumSize
sizeHint()
- PySide2.QtWidgets.QGraphicsLayoutItem.maximumWidth()¶
- Return type:
float
Returns the maximum width.
- PySide2.QtWidgets.QGraphicsLayoutItem.minimumHeight()¶
- Return type:
float
Returns the minimum height.
- PySide2.QtWidgets.QGraphicsLayoutItem.minimumSize()¶
- Return type:
Returns the minimum size.
See also
setMinimumSize()
preferredSize()
maximumSize()
MinimumSize
sizeHint()
- PySide2.QtWidgets.QGraphicsLayoutItem.minimumWidth()¶
- Return type:
float
Returns the minimum width.
- PySide2.QtWidgets.QGraphicsLayoutItem.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
QGraphicsItem
andQGraphicsLayoutItem
(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 theQGraphicsItem
hierarchy, so the parent layout should delete it. Subclasses might override this default behaviour by callingsetOwnedByLayout
(true).See also
- PySide2.QtWidgets.QGraphicsLayoutItem.parentLayoutItem()¶
- Return type:
Returns the parent of this
QGraphicsLayoutItem
, orNone
if there is no parent, or if the parent does not inherit fromQGraphicsLayoutItem
(QGraphicsLayoutItem
is often used through multiple inheritance withQObject
-derived classes).See also
- PySide2.QtWidgets.QGraphicsLayoutItem.preferredHeight()¶
- Return type:
float
Returns the preferred height.
- PySide2.QtWidgets.QGraphicsLayoutItem.preferredSize()¶
- Return type:
Returns the preferred size.
See also
setPreferredSize()
minimumSize()
maximumSize()
PreferredSize
sizeHint()
- PySide2.QtWidgets.QGraphicsLayoutItem.preferredWidth()¶
- Return type:
float
Returns the preferred width.
- PySide2.QtWidgets.QGraphicsLayoutItem.setGeometry(rect)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
This virtual function sets the geometry of the
QGraphicsLayoutItem
torect
, which is in parent coordinates (e.g., the top-left corner ofrect
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 ofminimumSize
andmaximumSize
, it will be adjusted to its closest size so that it is within the legal bounds.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setGraphicsItem(item)¶
- Parameters:
If the
QGraphicsLayoutItem
represents aQGraphicsItem
, and it wants to take advantage of the automatic reparenting capabilities of QGraphicsLayout it should set this value. Note that if you deleteitem
and not delete the layout item, you are responsible of calling (None
) in order to avoid having a dangling pointer.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setMaximumHeight(height)¶
- Parameters:
height – float
Sets the maximum height to
height
.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setMaximumSize(size)¶
- Parameters:
size –
PySide2.QtCore.QSizeF
Sets the maximum size to
size
. This property overridessizeHint()
forMaximumSize
and ensures thateffectiveSizeHint()
will never return a size larger thansize
. In order to unset the maximum size, use an invalid size.See also
maximumSize()
minimumSize()
preferredSize()
MaximumSize
sizeHint()
- PySide2.QtWidgets.QGraphicsLayoutItem.setMaximumSize(w, h)
- Parameters:
w – float
h – float
This convenience function is equivalent to calling
setMaximumSize
(QSizeF
(w
,h
)).
- PySide2.QtWidgets.QGraphicsLayoutItem.setMaximumWidth(width)¶
- Parameters:
width – float
Sets the maximum width to
width
.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setMinimumHeight(height)¶
- Parameters:
height – float
Sets the minimum height to
height
.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setMinimumSize(size)¶
- Parameters:
size –
PySide2.QtCore.QSizeF
Sets the minimum size to
size
. This property overridessizeHint()
forMinimumSize
and ensures thateffectiveSizeHint()
will never return a size smaller thansize
. In order to unset the minimum size, use an invalid size.See also
minimumSize()
maximumSize()
preferredSize()
MinimumSize
sizeHint()
setMinimumWidth()
setMinimumHeight()
- PySide2.QtWidgets.QGraphicsLayoutItem.setMinimumSize(w, h)
- Parameters:
w – float
h – float
This convenience function is equivalent to calling
setMinimumSize
(QSizeF
(w
,h
)).
- PySide2.QtWidgets.QGraphicsLayoutItem.setMinimumWidth(width)¶
- Parameters:
width – float
Sets the minimum width to
width
.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setOwnedByLayout(ownedByLayout)¶
- Parameters:
ownedByLayout – bool
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.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setParentLayoutItem(parent)¶
- Parameters:
Sets the parent of this
QGraphicsLayoutItem
toparent
.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.setPreferredHeight(height)¶
- Parameters:
height – float
Sets the preferred height to
height
.
- PySide2.QtWidgets.QGraphicsLayoutItem.setPreferredSize(size)¶
- Parameters:
size –
PySide2.QtCore.QSizeF
Sets the preferred size to
size
. This property overridessizeHint()
forPreferredSize
and provides the default value foreffectiveSizeHint()
. In order to unset the preferred size, use an invalid size.See also
preferredSize()
minimumSize()
maximumSize()
PreferredSize
sizeHint()
- PySide2.QtWidgets.QGraphicsLayoutItem.setPreferredSize(w, h)
- Parameters:
w – float
h – float
This convenience function is equivalent to calling
setPreferredSize
(QSizeF
(w
,h
)).
- PySide2.QtWidgets.QGraphicsLayoutItem.setPreferredWidth(width)¶
- Parameters:
width – float
Sets the preferred width to
width
.
- PySide2.QtWidgets.QGraphicsLayoutItem.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
- PySide2.QtWidgets.QGraphicsLayoutItem.setSizePolicy(policy)
- Parameters:
policy –
PySide2.QtWidgets.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, QGraphicsWidget defaults to (Preferred
,Preferred
,DefaultType
).See also
- PySide2.QtWidgets.QGraphicsLayoutItem.sizeHint(which[, constraint=QSizeF()])¶
- Parameters:
which –
SizeHint
constraint –
PySide2.QtCore.QSizeF
- Return type:
This pure virtual function returns the size hint for
which
of theQGraphicsLayoutItem
, using the width or height ofconstraint
to constrain the output.Reimplement this function in a subclass of
QGraphicsLayoutItem
to provide the necessary size hints for your items.See also
- PySide2.QtWidgets.QGraphicsLayoutItem.sizePolicy()¶
- Return type:
Returns the current size policy.
See also
- PySide2.QtWidgets.QGraphicsLayoutItem.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
© 2022 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 the GNU 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.