QGraphicsItem¶
The
QGraphicsItem
class is the base class for all graphical items in aQGraphicsScene
. More…
Inherited by: QAbstractGraphicsShapeItem, QGraphicsEllipseItem, QGraphicsItemGroup, QGraphicsLineItem, QGraphicsPathItem, QGraphicsPixmapItem, QGraphicsPolygonItem, QGraphicsRectItem, QGraphicsSimpleTextItem
Synopsis¶
Functions¶
def
acceptDrops
()def
acceptHoverEvents
()def
acceptTouchEvents
()def
acceptedMouseButtons
()def
addToIndex
()def
boundingRegion
(itemToDeviceTransform)def
boundingRegionGranularity
()def
cacheMode
()def
childItems
()def
childrenBoundingRect
()def
clearFocus
()def
clipPath
()def
collidingItems
([mode=Qt.IntersectsItemShape])def
commonAncestorItem
(other)def
cursor
()def
data
(key)def
deviceTransform
(viewportTransform)def
effectiveOpacity
()def
ensureVisible
([rect=QRectF()[, xmargin=50[, ymargin=50]]])def
ensureVisible
(x, y, w, h[, xmargin=50[, ymargin=50]])def
filtersChildEvents
()def
flags
()def
focusItem
()def
focusProxy
()def
focusScopeItem
()def
grabKeyboard
()def
grabMouse
()def
graphicsEffect
()def
group
()def
handlesChildEvents
()def
hasCursor
()def
hasFocus
()def
hide
()def
inputMethodHints
()def
installSceneEventFilter
(filterItem)def
isActive
()def
isAncestorOf
(child)def
isBlockedByModalPanel
()def
isClipped
()def
isEnabled
()def
isObscured
([rect=QRectF()])def
isObscured
(x, y, w, h)def
isPanel
()def
isSelected
()def
isUnderMouse
()def
isVisible
()def
isVisibleTo
(parent)def
isWidget
()def
isWindow
()def
itemTransform
(other)def
mapFromItem
(item, path)def
mapFromItem
(item, point)def
mapFromItem
(item, polygon)def
mapFromItem
(item, rect)def
mapFromItem
(item, x, y)def
mapFromItem
(item, x, y, w, h)def
mapFromParent
(path)def
mapFromParent
(point)def
mapFromParent
(polygon)def
mapFromParent
(rect)def
mapFromParent
(x, y)def
mapFromParent
(x, y, w, h)def
mapFromScene
(path)def
mapFromScene
(point)def
mapFromScene
(polygon)def
mapFromScene
(rect)def
mapFromScene
(x, y)def
mapFromScene
(x, y, w, h)def
mapRectFromItem
(item, rect)def
mapRectFromItem
(item, x, y, w, h)def
mapRectFromParent
(rect)def
mapRectFromParent
(x, y, w, h)def
mapRectFromScene
(rect)def
mapRectFromScene
(x, y, w, h)def
mapRectToItem
(item, rect)def
mapRectToItem
(item, x, y, w, h)def
mapRectToParent
(rect)def
mapRectToParent
(x, y, w, h)def
mapRectToScene
(rect)def
mapRectToScene
(x, y, w, h)def
mapToItem
(item, path)def
mapToItem
(item, point)def
mapToItem
(item, polygon)def
mapToItem
(item, rect)def
mapToItem
(item, x, y)def
mapToItem
(item, x, y, w, h)def
mapToParent
(path)def
mapToParent
(point)def
mapToParent
(polygon)def
mapToParent
(rect)def
mapToParent
(x, y)def
mapToParent
(x, y, w, h)def
mapToScene
(path)def
mapToScene
(point)def
mapToScene
(polygon)def
mapToScene
(rect)def
mapToScene
(x, y)def
mapToScene
(x, y, w, h)def
matrix
()def
moveBy
(dx, dy)def
opacity
()def
panel
()def
panelModality
()def
parentItem
()def
parentObject
()def
parentWidget
()def
pos
()def
prepareGeometryChange
()def
removeFromIndex
()def
removeSceneEventFilter
(filterItem)def
resetMatrix
()def
resetTransform
()def
rotation
()def
scale
()def
scene
()def
sceneBoundingRect
()def
sceneMatrix
()def
scenePos
()def
sceneTransform
()def
setAcceptDrops
(on)def
setAcceptHoverEvents
(enabled)def
setAcceptTouchEvents
(enabled)def
setAcceptedMouseButtons
(buttons)def
setActive
(active)def
setBoundingRegionGranularity
(granularity)def
setCacheMode
(mode[, cacheSize=QSize()])def
setCursor
(cursor)def
setData
(key, value)def
setEnabled
(enabled)def
setFiltersChildEvents
(enabled)def
setFlag
(flag[, enabled=true])def
setFlags
(flags)def
setFocus
([focusReason=Qt.OtherFocusReason])def
setFocusProxy
(item)def
setGraphicsEffect
(effect)def
setGroup
(group)def
setHandlesChildEvents
(enabled)def
setInputMethodHints
(hints)def
setMatrix
(matrix[, combine=false])def
setOpacity
(opacity)def
setPanelModality
(panelModality)def
setParentItem
(parent)def
setPos
(pos)def
setPos
(x, y)def
setRotation
(angle)def
setScale
(scale)def
setSelected
(selected)def
setToolTip
(toolTip)def
setTransform
(matrix[, combine=false])def
setTransformOriginPoint
(ax, ay)def
setTransformOriginPoint
(origin)def
setTransformations
(transformations)def
setVisible
(visible)def
setX
(x)def
setY
(y)def
setZValue
(z)def
show
()def
stackBefore
(sibling)def
toGraphicsObject
()def
toolTip
()def
topLevelItem
()def
topLevelWidget
()def
transform
()def
transformOriginPoint
()def
transformations
()def
ungrabKeyboard
()def
ungrabMouse
()def
unsetCursor
()def
update
([rect=QRectF()])def
update
(x, y, width, height)def
updateMicroFocus
()def
window
()def
x
()def
y
()def
zValue
()
Virtual functions¶
def
advance
(phase)def
boundingRect
()def
collidesWithItem
(other[, mode=Qt.IntersectsItemShape])def
collidesWithPath
(path[, mode=Qt.IntersectsItemShape])def
contains
(point)def
contextMenuEvent
(event)def
dragEnterEvent
(event)def
dragLeaveEvent
(event)def
dragMoveEvent
(event)def
dropEvent
(event)def
extension
(variant)def
focusInEvent
(event)def
focusOutEvent
(event)def
hoverEnterEvent
(event)def
hoverLeaveEvent
(event)def
hoverMoveEvent
(event)def
inputMethodEvent
(event)def
inputMethodQuery
(query)def
isObscuredBy
(item)def
itemChange
(change, value)def
keyPressEvent
(event)def
keyReleaseEvent
(event)def
mouseDoubleClickEvent
(event)def
mouseMoveEvent
(event)def
mousePressEvent
(event)def
mouseReleaseEvent
(event)def
opaqueArea
()def
paint
(painter, option[, widget=None])def
sceneEvent
(event)def
sceneEventFilter
(watched, event)def
shape
()def
type
()def
wheelEvent
(event)
Detailed Description¶
It provides a light-weight foundation for writing your own custom items. This includes defining the item’s geometry, collision detection, its painting implementation and item interaction through its event handlers.
QGraphicsItem
is part of the Graphics View FrameworkFor convenience, Qt provides a set of standard graphics items for the most common shapes. These are:
QGraphicsEllipseItem
provides an ellipse item
QGraphicsLineItem
provides a line item
QGraphicsPathItem
provides an arbitrary path item
QGraphicsPixmapItem
provides a pixmap item
QGraphicsPolygonItem
provides a polygon item
QGraphicsRectItem
provides a rectangular item
QGraphicsSimpleTextItem
provides a simple text label item
QGraphicsTextItem
provides an advanced text browser itemAll of an item’s geometric information is based on its local coordinate system. The item’s position,
pos()
, is the only function that does not operate in local coordinates, as it returns a position in parent coordinates. The Graphics View Coordinate System describes the coordinate system in detail.You can set whether an item should be visible (i.e., drawn, and accepting events), by calling
setVisible()
. Hiding an item will also hide its children. Similarly, you can enable or disable an item by callingsetEnabled()
. If you disable an item, all its children will also be disabled. By default, items are both visible and enabled. To toggle whether an item is selected or not, first enable selection by setting theItemIsSelectable
flag, and then callsetSelected()
. Normally, selection is toggled by the scene, as a result of user interaction.To write your own graphics item, you first create a subclass of
QGraphicsItem
, and then start by implementing its two pure virtual public functions:boundingRect()
, which returns an estimate of the area painted by the item, andpaint()
, which implements the actual painting. For example:class SimpleItem(QGraphicsItem): def boundingRect(self): penWidth = 1.0 return QRectF(-10 - penWidth / 2, -10 - penWidth / 2, 20 + penWidth, 20 + penWidth) def paint(self, painter, option, widget): painter.drawRoundedRect(-10, -10, 20, 20, 5, 5)The
boundingRect()
function has many different purposes.QGraphicsScene
bases its item index onboundingRect()
, andQGraphicsView
uses it both for culling invisible items, and for determining the area that needs to be recomposed when drawing overlapping items. In addition,QGraphicsItem
‘s collision detection mechanisms useboundingRect()
to provide an efficient cut-off. The fine grained collision algorithm incollidesWithItem()
is based on callingshape()
, which returns an accurate outline of the item’s shape as aQPainterPath
.
QGraphicsScene
expects all itemsboundingRect()
andshape()
to remain unchanged unless it is notified. If you want to change an item’s geometry in any way, you must first callprepareGeometryChange()
to allowQGraphicsScene
to update its bookkeeping.Collision detection can be done in two ways:
Reimplement
shape()
to return an accurate shape for your item, and rely on the default implementation ofcollidesWithItem()
to do shape-shape intersection. This can be rather expensive if the shapes are complex.Reimplement
collidesWithItem()
to provide your own custom item and shape collision algorithm.The
contains()
function can be called to determine whether the item contains a point or not. This function can also be reimplemented by the item. The default behavior ofcontains()
is based on callingshape()
.Items can contain other items, and also be contained by other items. All items can have a parent item and a list of children. Unless the item has no parent, its position is in parent coordinates (i.e., the parent’s local coordinates). Parent items propagate both their position and their transformation to all children.
Transformations¶
QGraphicsItem
supports projective transformations in addition to its base position,pos()
. There are several ways to change an item’s transformation. For simple transformations, you can call either of the convenience functionssetRotation()
orsetScale()
, or you can pass any transformation matrix tosetTransform()
. For advanced transformation control you also have the option of setting several combined transformations by callingsetTransformations()
.Item transformations accumulate from parent to child, so if both a parent and child item are rotated 90 degrees, the child’s total transformation will be 180 degrees. Similarly, if the item’s parent is scaled to 2x its original size, its children will also be twice as large. An item’s transformation does not affect its own local geometry; all geometry functions (e.g.,
contains()
,update()
, and all the mapping functions) still operate in local coordinates. For convenience,QGraphicsItem
provides the functionssceneTransform()
, which returns the item’s total transformation matrix (including its position and all parents’ positions and transformations), andscenePos()
, which returns its position in scene coordinates. To reset an item’s matrix, callresetTransform()
.Certain transformation operations produce a different outcome depending on the order in which they are applied. For example, if you scale an transform, and then rotate it, you may get a different result than if the transform was rotated first. However, the order you set the transformation properties on
QGraphicsItem
does not affect the resulting transformation;QGraphicsItem
always applies the properties in a fixed, defined order:
The item’s base transform is applied (
transform()
)The item’s transformations list is applied in order (
transformations()
)The item is rotated relative to its transform origin point (
rotation()
,transformOriginPoint()
)The item is scaled relative to its transform origin point (
scale()
,transformOriginPoint()
)
Painting¶
The
paint()
function is called byQGraphicsView
to paint the item’s contents. The item has no background or default fill of its own; whatever is behind the item will shine through all areas that are not explicitly painted in this function. You can callupdate()
to schedule a repaint, optionally passing the rectangle that needs a repaint. Depending on whether or not the item is visible in a view, the item may or may not be repainted; there is no equivalent torepaint()
inQGraphicsItem
.Items are painted by the view, starting with the parent items and then drawing children, in ascending stacking order. You can set an item’s stacking order by calling
setZValue()
, and test it by callingzValue()
, where items with low z-values are painted before items with high z-values. Stacking order applies to sibling items; parents are always drawn before their children.
Sorting¶
All items are drawn in a defined, stable order, and this same order decides which items will receive mouse input first when you click on the scene. Normally you don’t have to worry about sorting, as the items follow a “natural order”, following the logical structure of the scene.
An item’s children are stacked on top of the parent, and sibling items are stacked by insertion order (i.e., in the same order that they were either added to the scene, or added to the same parent). If you add item A, and then B, then B will be on top of A. If you then add C, the items’ stacking order will be A, then B, then C.
This example shows the stacking order of all limbs of the robot from the Drag and Drop Robot example. The torso is the root item (all other items are children or descendants of the torso), so it is drawn first. Next, the head is drawn, as it is the first item in the torso’s list of children. Then the upper left arm is drawn. As the lower arm is a child of the upper arm, the lower arm is then drawn, followed by the upper arm’s next sibling, which is the upper right arm, and so on.
For advanced users, there are ways to alter how your items are sorted:
You can call
setZValue()
on an item to explicitly stack it on top of, or under, other sibling items. The default Z value for an item is 0. Items with the same Z value are stacked by insertion order.You can call
stackBefore()
to reorder the list of children. This will directly modify the insertion order.You can set the
ItemStacksBehindParent
flag to stack a child item behind its parent.The stacking order of two sibling items also counts for each item’s children and descendant items. So if one item is on top of another, then all its children will also be on top of all the other item’s children as well.
Events¶
QGraphicsItem
receives events fromQGraphicsScene
through the virtual functionsceneEvent()
. This function distributes the most common events to a set of convenience event handlers:
contextMenuEvent()
handles context menu events
focusInEvent()
andfocusOutEvent()
handle focus in and out events
hoverEnterEvent()
,hoverMoveEvent()
, andhoverLeaveEvent()
handles hover enter, move and leave events
inputMethodEvent()
handles input events, for accessibility support
keyPressEvent()
andkeyReleaseEvent()
handle key press and release events
mousePressEvent()
,mouseMoveEvent()
,mouseReleaseEvent()
, andmouseDoubleClickEvent()
handles mouse press, move, release, click and double-click eventsYou can filter events for any other item by installing event filters. This functionality is separate from Qt’s regular event filters (see
installEventFilter()
), which only work on subclasses ofQObject
. After installing your item as an event filter for another item by callinginstallSceneEventFilter()
, the filtered events will be received by the virtual functionsceneEventFilter()
. You can remove item event filters by callingremoveSceneEventFilter()
.
Custom Data¶
Sometimes it’s useful to register custom data with an item, be it a custom item, or a standard item. You can call
setData()
on any item to store data in it using a key-value pair (the key being an integer, and the value is aQVariant
). To get custom data from an item, calldata()
. This functionality is completely untouched by Qt itself; it is provided for the user’s convenience.
- class PySide2.QtWidgets.QGraphicsItem([parent=None])¶
- param parent:
Constructs a
QGraphicsItem
with the givenparent
item. It does not modify the parent object returned byparent()
.If
parent
isNone
, you can add the item to a scene by callingaddItem()
. The item will then become a top-level item.See also
- PySide2.QtWidgets.QGraphicsItem.GraphicsItemFlag¶
This enum describes different flags that you can set on an item to toggle different features in the item’s behavior.
All flags are disabled by default.
Constant
Description
QGraphicsItem.ItemIsMovable
The item supports interactive movement using the mouse. By clicking on the item and then dragging, the item will move together with the mouse cursor. If the item has children, all children are also moved. If the item is part of a selection, all selected items are also moved. This feature is provided as a convenience through the base implementation of
QGraphicsItem
‘s mouse event handlers.QGraphicsItem.ItemIsSelectable
The item supports selection. Enabling this feature will enable
setSelected()
to toggle selection for the item. It will also let the item be selected automatically as a result of callingsetSelectionArea()
, by clicking on an item, or by using rubber band selection inQGraphicsView
.QGraphicsItem.ItemIsFocusable
The item supports keyboard input focus (i.e., it is an input item). Enabling this flag will allow the item to accept focus, which again allows the delivery of key events to
keyPressEvent()
andkeyReleaseEvent()
.QGraphicsItem.ItemClipsToShape
The item clips to its own shape. The item cannot draw or receive mouse, tablet, drag and drop or hover events outside its shape. It is disabled by default. This behavior is enforced by
drawItems()
ordrawItems()
. This flag was introduced in Qt 4.3.QGraphicsItem.ItemClipsChildrenToShape
The item clips the painting of all its descendants to its own shape. Items that are either direct or indirect children of this item cannot draw outside this item’s shape. By default, this flag is disabled; children can draw anywhere. This behavior is enforced by
drawItems()
ordrawItems()
. This flag was introduced in Qt 4.3.Note
This flag is similar to but in addition enforces the containment by clipping the children.
Constant
Description
QGraphicsItem.ItemIgnoresTransformations
The item ignores inherited transformations (i.e., its position is still anchored to its parent, but the parent or view rotation, zoom or shear transformations are ignored). This flag is useful for keeping text label items horizontal and unscaled, so they will still be readable if the view is transformed. When set, the item’s view geometry and scene geometry will be maintained separately. You must call
deviceTransform()
to map coordinates and detect collisions in the view. By default, this flag is disabled. This flag was introduced in Qt 4.3.Note
With this flag set you can still scale the item itself, and that scale transformation will influence the item’s children.
Constant
Description
QGraphicsItem.ItemIgnoresParentOpacity
The item ignores its parent’s opacity. The item’s effective opacity is the same as its own; it does not combine with the parent’s opacity. This flags allows your item to keep its absolute opacity even if the parent is semitransparent. This flag was introduced in Qt 4.5.
QGraphicsItem.ItemDoesntPropagateOpacityToChildren
The item doesn’t propagate its opacity to its children. This flag allows you to create a semitransparent item that does not affect the opacity of its children. This flag was introduced in Qt 4.5.
QGraphicsItem.ItemStacksBehindParent
The item is stacked behind its parent. By default, child items are stacked on top of the parent item. But setting this flag, the child will be stacked behind it. This flag is useful for drop shadow effects and for decoration objects that follow the parent item’s geometry without drawing on top of it. This flag was introduced in Qt 4.5.
QGraphicsItem.ItemUsesExtendedStyleOption
The item makes use of either exposedRect or matrix in
QStyleOptionGraphicsItem
. By default, the exposedRect is initialized to the item’sboundingRect()
and the matrix is untransformed. You can enable this flag for the style options to be set up with more fine-grained values. Note that QStyleOptionGraphicsItem::levelOfDetail is unaffected by this flag and always initialized to 1. UselevelOfDetailFromTransform()
if you need a higher value. This flag was introduced in Qt 4.6.QGraphicsItem.ItemHasNoContents
The item does not paint anything (i.e., calling
paint()
on the item has no effect). You should set this flag on items that do not need to be painted to ensure that Graphics View avoids unnecessary painting preparations. This flag was introduced in Qt 4.6.QGraphicsItem.ItemSendsGeometryChanges
The item enables
itemChange()
notifications forItemPositionChange
,ItemPositionHasChanged
,ItemTransformChange
,ItemTransformHasChanged
,ItemRotationChange
,ItemRotationHasChanged
,ItemScaleChange
,ItemScaleHasChanged
,ItemTransformOriginPointChange
, andItemTransformOriginPointHasChanged
. For performance reasons, these notifications are disabled by default. You must enable this flag to receive notifications for position and transform changes. This flag was introduced in Qt 4.6.QGraphicsItem.ItemAcceptsInputMethod
The item supports input methods typically used for Asian languages. This flag was introduced in Qt 4.6.
QGraphicsItem.ItemNegativeZStacksBehindParent
The item automatically stacks behind it’s parent if it’s z-value is negative. This flag enables
setZValue()
to toggle . This flag was introduced in Qt 4.6.QGraphicsItem.ItemIsPanel
The item is a panel. A panel provides activation and contained focus handling. Only one panel can be active at a time (see
isActive()
). When no panel is active,QGraphicsScene
activates all non-panel items. Window items (i.e.,isWindow()
returnstrue
) are panels. This flag was introduced in Qt 4.6.QGraphicsItem.ItemSendsScenePositionChanges
The item enables
itemChange()
notifications forItemScenePositionHasChanged
. For performance reasons, these notifications are disabled by default. You must enable this flag to receive notifications for scene position changes. This flag was introduced in Qt 4.6.QGraphicsItem.ItemContainsChildrenInShape
This flag indicates that all of the item’s direct or indirect children only draw within the item’s shape. Unlike , this restriction is not enforced. Set when you manually assure that drawing is bound to the item’s shape and want to avoid the cost associated with enforcing the clip. Setting this flag enables more efficient drawing and collision detection. The flag is disabled by default.
Note
If both this flag and are set, the clip will be enforced. This is equivalent to just setting .
This flag was introduced in Qt 5.4.
- PySide2.QtWidgets.QGraphicsItem.GraphicsItemChange¶
This enum describes the state changes that are notified by
itemChange()
. The notifications are sent as the state changes, and in some cases, adjustments can be made (see the documentation for each change for details).Note: Be careful with calling functions on the
QGraphicsItem
itself insideitemChange()
, as certain function calls can lead to unwanted recursion. For example, you cannot callsetPos()
initemChange()
on an notification, as thesetPos()
function will again callitemChange
(). Instead, you can return the new, adjusted position fromitemChange()
.Constant
Description
QGraphicsItem.ItemEnabledChange
The item’s enabled state changes. If the item is presently enabled, it will become disabled, and vice verca. The value argument is the new enabled state (i.e., true or false). Do not call
setEnabled()
initemChange()
as this notification is delivered. Instead, you can return the new state fromitemChange()
.QGraphicsItem.ItemEnabledHasChanged
The item’s enabled state has changed. The value argument is the new enabled state (i.e., true or false). Do not call
setEnabled()
initemChange()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemMatrixChange
The item’s affine transformation matrix is changing. This value is obsolete; you can use instead.
QGraphicsItem.ItemPositionChange
The item’s position changes. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and when the item’s local position changes, relative to its parent (i.e., as a result of callingsetPos()
ormoveBy()
). The value argument is the new position (i.e., aQPointF
). You can callpos()
to get the original position. Do not callsetPos()
ormoveBy()
initemChange()
as this notification is delivered; instead, you can return the new, adjusted position fromitemChange()
. After this notification,QGraphicsItem
immediately sends the notification if the position changed.QGraphicsItem.ItemPositionHasChanged
The item’s position has changed. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and after the item’s local position, relative to its parent, has changed. The value argument is the new position (the same aspos()
), andQGraphicsItem
ignores the return value for this notification (i.e., a read-only notification).QGraphicsItem.ItemTransformChange
The item’s transformation matrix changes. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and when the item’s local transformation matrix changes (i.e., as a result of callingsetTransform()
. The value argument is the new matrix (i.e., aQTransform
); to get the old matrix, calltransform()
. Do not callsetTransform()
or set any of the transformation properties initemChange()
as this notification is delivered; instead, you can return the new matrix fromitemChange()
. This notification is not sent if you change the transformation properties.QGraphicsItem.ItemTransformHasChanged
The item’s transformation matrix has changed either because
setTransform
is called, or one of the transformation properties is changed. This notification is sent if theItemSendsGeometryChanges
flag is enabled, and after the item’s local transformation matrix has changed. The value argument is the new matrix (same astransform()
), andQGraphicsItem
ignores the return value for this notification (i.e., a read-only notification).QGraphicsItem.ItemRotationChange
The item’s rotation property changes. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and when the item’s rotation property changes (i.e., as a result of callingsetRotation()
). The value argument is the new rotation (i.e., a double); to get the old rotation, callrotation()
. Do not callsetRotation()
initemChange()
as this notification is delivered; instead, you can return the new rotation fromitemChange()
.QGraphicsItem.ItemRotationHasChanged
The item’s rotation property has changed. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and after the item’s rotation property has changed. The value argument is the new rotation (i.e., a double), andQGraphicsItem
ignores the return value for this notification (i.e., a read-only notification). Do not callsetRotation()
initemChange()
as this notification is delivered.QGraphicsItem.ItemScaleChange
The item’s scale property changes. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and when the item’s scale property changes (i.e., as a result of callingsetScale()
). The value argument is the new scale (i.e., a double); to get the old scale, callscale()
. Do not callsetScale()
initemChange()
as this notification is delivered; instead, you can return the new scale fromitemChange()
.QGraphicsItem.ItemScaleHasChanged
The item’s scale property has changed. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and after the item’s scale property has changed. The value argument is the new scale (i.e., a double), andQGraphicsItem
ignores the return value for this notification (i.e., a read-only notification). Do not callsetScale()
initemChange()
as this notification is delivered.QGraphicsItem.ItemTransformOriginPointChange
The item’s transform origin point property changes. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and when the item’s transform origin point property changes (i.e., as a result of callingsetTransformOriginPoint()
). The value argument is the new origin point (i.e., aQPointF
); to get the old origin point, calltransformOriginPoint()
. Do not callsetTransformOriginPoint()
initemChange()
as this notification is delivered; instead, you can return the new transform origin point fromitemChange()
.QGraphicsItem.ItemTransformOriginPointHasChanged
The item’s transform origin point property has changed. This notification is sent if the
ItemSendsGeometryChanges
flag is enabled, and after the item’s transform origin point property has changed. The value argument is the new origin point (i.e., aQPointF
), andQGraphicsItem
ignores the return value for this notification (i.e., a read-only notification). Do not callsetTransformOriginPoint()
initemChange()
as this notification is delivered.QGraphicsItem.ItemSelectedChange
The item’s selected state changes. If the item is presently selected, it will become unselected, and vice verca. The value argument is the new selected state (i.e., true or false). Do not call
setSelected()
initemChange()
as this notification is delivered; instead, you can return the new selected state fromitemChange()
.QGraphicsItem.ItemSelectedHasChanged
The item’s selected state has changed. The value argument is the new selected state (i.e., true or false). Do not call
setSelected()
initemChange()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemVisibleChange
The item’s visible state changes. If the item is presently visible, it will become invisible, and vice verca. The value argument is the new visible state (i.e., true or false). Do not call
setVisible()
initemChange()
as this notification is delivered; instead, you can return the new visible state fromitemChange()
.QGraphicsItem.ItemVisibleHasChanged
The item’s visible state has changed. The value argument is the new visible state (i.e., true or false). Do not call
setVisible()
initemChange()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemParentChange
The item’s parent changes. The value argument is the new parent item (i.e., a
QGraphicsItem
pointer). Do not callsetParentItem()
initemChange()
as this notification is delivered; instead, you can return the new parent fromitemChange()
.QGraphicsItem.ItemParentHasChanged
The item’s parent has changed. The value argument is the new parent (i.e., a pointer to a
QGraphicsItem
). Do not callsetParentItem()
initemChange()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemChildAddedChange
A child is added to this item. The value argument is the new child item (i.e., a
QGraphicsItem
pointer). Do not pass this item to any item’ssetParentItem()
function as this notification is delivered. The return value is unused; you cannot adjust anything in this notification. Note that the new child might not be fully constructed when this notification is sent; calling pure virtual functions on the child can lead to a crash.QGraphicsItem.ItemChildRemovedChange
A child is removed from this item. The value argument is the child item that is about to be removed (i.e., a
QGraphicsItem
pointer). The return value is unused; you cannot adjust anything in this notification.QGraphicsItem.ItemSceneChange
The item is moved to a new scene. This notification is also sent when the item is added to its initial scene, and when it is removed. The item’s
scene()
is the old scene, orNone
if the item has not been added to a scene yet. The value argument is the new scene (i.e., aQGraphicsScene
pointer), orNone
if the item is removed from a scene. Do not override this change by passing this item toaddItem()
as this notification is delivered; instead, you can return the new scene fromitemChange()
. Use this feature with caution; objecting to a scene change can quickly lead to unwanted recursion.QGraphicsItem.ItemSceneHasChanged
The item’s scene has changed. The item’s
scene()
is the new scene. This notification is also sent when the item is added to its initial scene, and when it is removed.The value argument is the new scene (i.e., a pointer to aQGraphicsScene
). Do not call setScene() initemChange()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemCursorChange
The item’s cursor changes. The value argument is the new cursor (i.e., a
QCursor
). Do not callsetCursor()
initemChange()
as this notification is delivered. Instead, you can return a new cursor fromitemChange()
.QGraphicsItem.ItemCursorHasChanged
The item’s cursor has changed. The value argument is the new cursor (i.e., a
QCursor
). Do not callsetCursor()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemToolTipChange
The item’s tooltip changes. The value argument is the new tooltip (i.e., a
QToolTip
). Do not callsetToolTip()
initemChange()
as this notification is delivered. Instead, you can return a new tooltip fromitemChange()
.QGraphicsItem.ItemToolTipHasChanged
The item’s tooltip has changed. The value argument is the new tooltip (i.e., a
QToolTip
). Do not callsetToolTip()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemFlagsChange
The item’s flags change. The value argument is the new flags (i.e., a quint32). Do not call
setFlags()
initemChange()
as this notification is delivered. Instead, you can return the new flags fromitemChange()
.QGraphicsItem.ItemFlagsHaveChanged
The item’s flags have changed. The value argument is the new flags (i.e., a quint32). Do not call
setFlags()
initemChange()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemZValueChange
The item’s Z-value changes. The value argument is the new Z-value (i.e., a double). Do not call
setZValue()
initemChange()
as this notification is delivered. Instead, you can return a new Z-value fromitemChange()
.QGraphicsItem.ItemZValueHasChanged
The item’s Z-value has changed. The value argument is the new Z-value (i.e., a double). Do not call
setZValue()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemOpacityChange
The item’s opacity changes. The value argument is the new opacity (i.e., a double). Do not call
setOpacity()
initemChange()
as this notification is delivered. Instead, you can return a new opacity fromitemChange()
.QGraphicsItem.ItemOpacityHasChanged
The item’s opacity has changed. The value argument is the new opacity (i.e., a double). Do not call
setOpacity()
as this notification is delivered. The return value is ignored.QGraphicsItem.ItemScenePositionHasChanged
The item’s scene position has changed. This notification is sent if the
ItemSendsScenePositionChanges
flag is enabled, and after the item’s scene position has changed (i.e., the position or transformation of the item itself or the position or transformation of any ancestor has changed). The value argument is the new scene position (the same asscenePos()
), andQGraphicsItem
ignores the return value for this notification (i.e., a read-only notification).
- PySide2.QtWidgets.QGraphicsItem.CacheMode¶
This enum describes
QGraphicsItem
‘s cache modes. Caching is used to speed up rendering by allocating and rendering to an off-screen pixel buffer, which can be reused when the item requires redrawing. For some paint devices, the cache is stored directly in graphics memory, which makes rendering very quick.Constant
Description
QGraphicsItem.NoCache
The default; all item caching is disabled.
paint()
is called every time the item needs redrawing.QGraphicsItem.ItemCoordinateCache
Caching is enabled for the item’s logical (local) coordinate system.
QGraphicsItem
creates an off-screen pixel buffer with a configurable size / resolution that you can pass tosetCacheMode()
. Rendering quality will typically degrade, depending on the resolution of the cache and the item transformation. The first time the item is redrawn, it will render itself into the cache, and the cache is then reused for every subsequent expose. The cache is also reused as the item is transformed. To adjust the resolution of the cache, you can callsetCacheMode()
again.QGraphicsItem.DeviceCoordinateCache
Caching is enabled at the paint device level, in device coordinates. This mode is for items that can move, but are not rotated, scaled or sheared. If the item is transformed directly or indirectly, the cache will be regenerated automatically. Unlike ItemCoordinateCacheMode, always renders at maximum quality.
See also
- PySide2.QtWidgets.QGraphicsItem.PanelModality¶
This enum specifies the behavior of a modal panel. A modal panel is one that blocks input to other panels. Note that items that are children of a modal panel are not blocked.
The values are:
Constant
Description
QGraphicsItem.NonModal
The panel is not modal and does not block input to other panels. This is the default value for panels.
QGraphicsItem.PanelModal
The panel is modal to a single item hierarchy and blocks input to its parent pane, all grandparent panels, and all siblings of its parent and grandparent panels.
QGraphicsItem.SceneModal
The window is modal to the entire scene and blocks input to all panels.
See also
setPanelModality()
panelModality()
ItemIsPanel
New in version 4.6.
- PySide2.QtWidgets.QGraphicsItem.Extension¶
Note: This is provided as a hook to avoid future problems related to adding virtual functions. See also , and .
- PySide2.QtWidgets.QGraphicsItem.acceptDrops()¶
- Return type:
bool
Returns
true
if this item can accept drag and drop events; otherwise, returnsfalse
. By default, items do not accept drag and drop events; items are transparent to drag and drop.See also
- PySide2.QtWidgets.QGraphicsItem.acceptHoverEvents()¶
- Return type:
bool
Returns
true
if an item accepts hover events (QGraphicsSceneHoverEvent
); otherwise, returnsfalse
. By default, items do not accept hover events.
- PySide2.QtWidgets.QGraphicsItem.acceptTouchEvents()¶
- Return type:
bool
Returns
true
if an item acceptstouch events
; otherwise, returnsfalse
. By default, items do not accept touch events.See also
- PySide2.QtWidgets.QGraphicsItem.acceptedMouseButtons()¶
- Return type:
MouseButtons
Returns the mouse buttons that this item accepts mouse events for. By default, all mouse buttons are accepted.
If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that mouse button. However, if the item does not accept the button,
QGraphicsScene
will forward the mouse events to the first item beneath it that does.
- PySide2.QtWidgets.QGraphicsItem.addToIndex()¶
Adds this item to the scene’s index. Called in conjunction with to ensure the index bookkeeping is correct when the item’s position, transformation or shape changes.
- PySide2.QtWidgets.QGraphicsItem.advance(phase)¶
- Parameters:
phase – int
This virtual function is called twice for all items by the
advance()
slot. In the first phase, all items are called withphase
== 0, indicating that items on the scene are about to advance, and then all items are called withphase
== 1. Reimplement this function to update your item if you need simple scene-controlled animation.The default implementation does nothing.
This function is intended for animations. An alternative is to multiple-inherit from
QObject
andQGraphicsItem
and use the Animation Framework .See also
advance()
QTimeLine
- PySide2.QtWidgets.QGraphicsItem.boundingRect()¶
- Return type:
This pure virtual function defines the outer bounds of the item as a rectangle; all painting must be restricted to inside an item’s bounding rect.
QGraphicsView
uses this to determine whether the item requires redrawing.Although the item’s shape can be arbitrary, the bounding rect is always rectangular, and it is unaffected by the items’ transformation.
If you want to change the item’s bounding rectangle, you must first call
prepareGeometryChange()
. This notifies the scene of the imminent change, so that it can update its item geometry index; otherwise, the scene will be unaware of the item’s new geometry, and the results are undefined (typically, rendering artifacts are left within the view).Reimplement this function to let
QGraphicsView
determine what parts of the widget, if any, need to be redrawn.Note: For shapes that paint an outline / stroke, it is important to include half the pen width in the bounding rect. It is not necessary to compensate for antialiasing, though.
Example:
def boundingRect(self): penWidth = 1.0 return QRectF(-radius - penWidth / 2, -radius - penWidth / 2, diameter + penWidth, diameter + penWidth)
- PySide2.QtWidgets.QGraphicsItem.boundingRegion(itemToDeviceTransform)¶
- Parameters:
itemToDeviceTransform –
PySide2.QtGui.QTransform
- Return type:
Returns the bounding region for this item. The coordinate space of the returned region depends on
itemToDeviceTransform
. If you pass an identityQTransform
as a parameter, this function will return a local coordinate region.The bounding region describes a coarse outline of the item’s visual contents. Although it’s expensive to calculate, it’s also more precise than
boundingRect()
, and it can help to avoid unnecessary repainting when an item is updated. This is particularly efficient for thin items (e.g., lines or simple polygons). You can tune the granularity for the bounding region by callingsetBoundingRegionGranularity()
. The default granularity is 0; in which the item’s bounding region is the same as its bounding rect.itemToDeviceTransform
is the transformation from item coordinates to device coordinates. If you want this function to return aQRegion
in scene coordinates, you can passsceneTransform()
as an argument.See also
- PySide2.QtWidgets.QGraphicsItem.boundingRegionGranularity()¶
- Return type:
float
Returns the item’s bounding region granularity; a value between and including 0 and 1. The default value is 0 (i.e., the lowest granularity, where the bounding region corresponds to the item’s bounding rectangle).
See also
- PySide2.QtWidgets.QGraphicsItem.cacheMode()¶
- Return type:
Returns the cache mode for this item. The default mode is
NoCache
(i.e., cache is disabled and all painting is immediate).See also
- PySide2.QtWidgets.QGraphicsItem.childItems()¶
- Return type:
Returns a list of this item’s children.
The items are sorted by stacking order. This takes into account both the items’ insertion order and their Z-values.
See also
setParentItem()
zValue()
Sorting
- PySide2.QtWidgets.QGraphicsItem.childrenBoundingRect()¶
- Return type:
Returns the bounding rect of this item’s descendants (i.e., its children, their children, etc.) in local coordinates. The rectangle will contain all descendants after they have been mapped to local coordinates. If the item has no children, this function returns an empty
QRectF
.This does not include this item’s own bounding rect; it only returns its descendants’ accumulated bounding rect. If you need to include this item’s bounding rect, you can add
boundingRect()
to using QRectF::operator|().This function is linear in complexity; it determines the size of the returned bounding rect by iterating through all descendants.
See also
- PySide2.QtWidgets.QGraphicsItem.clearFocus()¶
Takes keyboard input focus from the item.
If it has focus, a
focus out event
is sent to this item to tell it that it is about to lose the focus.Only items that set the
ItemIsFocusable
flag, or widgets that set an appropriate focus policy, can accept keyboard focus.See also
- PySide2.QtWidgets.QGraphicsItem.clipPath()¶
- Return type:
Returns this item’s clip path, or an empty
QPainterPath
if this item is not clipped. The clip path constrains the item’s appearance and interaction (i.e., restricts the area the item can draw within and receive events for).You can enable clipping by setting the
ItemClipsToShape
orItemClipsChildrenToShape
flags. The item’s clip path is calculated by intersecting all clipping ancestors’ shapes. If the item setsItemClipsToShape
, the final clip is intersected with the item’s own shape.Note
Clipping introduces a performance penalty for all items involved; you should generally avoid using clipping if you can (e.g., if your items always draw inside
boundingRect()
orshape()
boundaries, clipping is not necessary).See also
- PySide2.QtWidgets.QGraphicsItem.collidesWithItem(other[, mode=Qt.IntersectsItemShape])¶
- Parameters:
other –
PySide2.QtWidgets.QGraphicsItem
mode –
ItemSelectionMode
- Return type:
bool
Returns
true
if this item collides withother
; otherwise returnsfalse
.The
mode
is applied toother
, and the resulting shape or bounding rectangle is then compared to this item’s shape. The default value formode
isIntersectsItemShape
;other
collides with this item if it either intersects, contains, or is contained by this item’s shape (seeItemSelectionMode
for details).The default implementation is based on shape intersection, and it calls
shape()
on both items. Because the complexity of arbitrary shape-shape intersection grows with an order of magnitude when the shapes are complex, this operation can be noticeably time-consuming. You have the option of reimplementing this function in a subclass ofQGraphicsItem
to provide a custom algorithm. This allows you to make use of natural constraints in the shapes of your own items, in order to improve the performance of the collision detection. For instance, two untransformed perfectly circular items’ collision can be determined very efficiently by comparing their positions and radii.Keep in mind that when reimplementing this function and calling
shape()
orboundingRect()
onother
, the returned coordinates must be mapped to this item’s coordinate system before any intersection can take place.See also
- PySide2.QtWidgets.QGraphicsItem.collidesWithPath(path[, mode=Qt.IntersectsItemShape])¶
- Parameters:
path –
PySide2.QtGui.QPainterPath
mode –
ItemSelectionMode
- Return type:
bool
Returns
true
if this item collides withpath
.The collision is determined by
mode
. The default value formode
isIntersectsItemShape
;path
collides with this item if it either intersects, contains, or is contained by this item’s shape.Note that this function checks whether the item’s shape or bounding rectangle (depending on
mode
) is contained withinpath
, and not whetherpath
is contained within the items shape or bounding rectangle.See also
- PySide2.QtWidgets.QGraphicsItem.collidingItems([mode=Qt.IntersectsItemShape])¶
- Parameters:
mode –
ItemSelectionMode
- Return type:
Returns a list of all items that collide with this item.
The way collisions are detected is determined by applying
mode
to items that are compared to this item, i.e., each item’s shape or bounding rectangle is checked against this item’s shape. The default value formode
isIntersectsItemShape
.See also
- PySide2.QtWidgets.QGraphicsItem.commonAncestorItem(other)¶
- Parameters:
other –
PySide2.QtWidgets.QGraphicsItem
- Return type:
Returns the closest common ancestor item of this item and
other
, orNone
if eitherother
isNone
, or there is no common ancestor.See also
- PySide2.QtWidgets.QGraphicsItem.contains(point)¶
- Parameters:
point –
PySide2.QtCore.QPointF
- Return type:
bool
Returns
true
if this item containspoint
, which is in local coordinates; otherwise, false is returned. It is most often called fromQGraphicsView
to determine what item is under the cursor, and for that reason, the implementation of this function should be as light-weight as possible.By default, this function calls
shape()
, but you can reimplement it in a subclass to provide a (perhaps more efficient) implementation.See also
- PySide2.QtWidgets.QGraphicsItem.contextMenuEvent(event)¶
- Parameters:
This event handler can be reimplemented in a subclass to process context menu events. The
event
parameter contains details about the event to be handled.If you ignore the event (i.e., by calling
ignore()
),event
will propagate to any item beneath this item. If no items accept the event, it will be ignored by the scene and propagate to the view.It’s common to open a
QMenu
in response to receiving a context menu event. Example:def contextMenuEvent(self, event): menu = QMenu() removeAction = menu.addAction("Remove") markAction = menu.addAction("Mark") selectedAction = menu.exec(event.screenPos()) // ...
The default implementation ignores the event.
See also
- PySide2.QtWidgets.QGraphicsItem.cursor()¶
- Return type:
Returns the current cursor shape for the item. The mouse cursor will assume this shape when it’s over this item. See the
list of predefined cursor objects
for a range of useful shapes.An editor item might want to use an I-beam cursor:
item.setCursor(Qt.IBeamCursor)
If no cursor has been set, the cursor of the item beneath is used.
See also
setCursor()
hasCursor()
unsetCursor()
cursor
overrideCursor()
- PySide2.QtWidgets.QGraphicsItem.data(key)¶
- Parameters:
key – int
- Return type:
object
Returns this item’s custom data for the key
key
as aQVariant
.Custom item data is useful for storing arbitrary properties in any item. Example:
ObjectName = 0; item = scene.itemAt(100, 50) if len(item.data(ObjectName)) == 0: if isinstance(ButtonItem, item): item.setData(ObjectName, "Button")
Qt does not use this feature for storing data; it is provided solely for the convenience of the user.
See also
- PySide2.QtWidgets.QGraphicsItem.deviceTransform(viewportTransform)¶
- Parameters:
viewportTransform –
PySide2.QtGui.QTransform
- Return type:
Returns this item’s device transformation matrix, using
viewportTransform
to map from scene to device coordinates. This matrix can be used to map coordinates and geometrical shapes from this item’s local coordinate system to the viewport’s (or any device’s) coordinate system. To map coordinates from the viewport, you must first invert the returned matrix.Example:
rect = QGraphicsRectItem() rect.setPos(100, 100) rect.deviceTransform(view.viewportTransform()).map(QPointF(0, 0)) # returns the item's (0, 0) point in view's viewport coordinates rect.deviceTransform(view.viewportTransform()).inverted().map(QPointF(100, 100)) # returns view's viewport's (100, 100) coordinate in item coordinates
This function is the same as combining this item’s scene transform with the view’s viewport transform, but it also understands the
ItemIgnoresTransformations
flag. The device transform can be used to do accurate coordinate mapping (and collision detection) for untransformable items.
- PySide2.QtWidgets.QGraphicsItem.dragEnterEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive drag enter events for this item. Drag enter events are generated as the cursor enters the item’s area.By accepting the event (i.e., by calling
accept()
), the item will accept drop events, in addition to receiving drag move and drag leave. Otherwise, the event will be ignored and propagate to the item beneath. If the event is accepted, the item will receive a drag move event before control goes back to the event loop.A common implementation of accepts or ignores
event
depending on the associated mime data inevent
. Example:def __init__(self): self.setAcceptDrops(true) ... def dragEnterEvent(self, event): event.setAccepted(event.mimeData().hasFormat("text/plain"))
Items do not receive drag and drop events by default; to enable this feature, call
setAcceptDrops(true)
.The default implementation does nothing.
See also
- PySide2.QtWidgets.QGraphicsItem.dragLeaveEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive drag leave events for this item. Drag leave events are generated as the cursor leaves the item’s area. Most often you will not need to reimplement this function, but it can be useful for resetting state in your item (e.g., highlighting).Calling
ignore()
oraccept()
onevent
has no effect.Items do not receive drag and drop events by default; to enable this feature, call
setAcceptDrops(true)
.The default implementation does nothing.
See also
- PySide2.QtWidgets.QGraphicsItem.dragMoveEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive drag move events for this item. Drag move events are generated as the cursor moves around inside the item’s area. Most often you will not need to reimplement this function; it is used to indicate that only parts of the item can accept drops.Calling
ignore()
oraccept()
onevent
toggles whether or not the item will accept drops at the position from the event. By default,event
is accepted, indicating that the item allows drops at the specified position.Items do not receive drag and drop events by default; to enable this feature, call
setAcceptDrops(true)
.The default implementation does nothing.
See also
- PySide2.QtWidgets.QGraphicsItem.dropEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive drop events for this item. Items can only receive drop events if the last drag move event was accepted.Calling
ignore()
oraccept()
onevent
has no effect.Items do not receive drag and drop events by default; to enable this feature, call
setAcceptDrops(true)
.The default implementation does nothing.
- PySide2.QtWidgets.QGraphicsItem.effectiveOpacity()¶
- Return type:
float
Returns this item’s effective opacity, which is between 0.0 (transparent) and 1.0 (opaque). This value is a combination of this item’s local opacity, and its parent and ancestors’ opacities. The effective opacity decides how the item is rendered.
See also
opacity()
setOpacity()
paint()
ItemIgnoresParentOpacity
ItemDoesntPropagateOpacityToChildren
- PySide2.QtWidgets.QGraphicsItem.ensureVisible([rect=QRectF()[, xmargin=50[, ymargin=50]]])¶
- Parameters:
rect –
PySide2.QtCore.QRectF
xmargin – int
ymargin – int
If this item is part of a scene that is viewed by a
QGraphicsView
, this convenience function will attempt to scroll the view to ensure thatrect
is visible inside the view’s viewport. Ifrect
is a null rect (the default),QGraphicsItem
will default to the item’s bounding rect.xmargin
andymargin
are the number of pixels the view should use for margins.If the specified rect cannot be reached, the contents are scrolled to the nearest valid position.
If this item is not viewed by a
QGraphicsView
, this function does nothing.See also
- PySide2.QtWidgets.QGraphicsItem.ensureVisible(x, y, w, h[, xmargin=50[, ymargin=50]])
- Parameters:
x – float
y – float
w – float
h – float
xmargin – int
ymargin – int
This convenience function is equivalent to calling
ensureVisible
(QRectF
(x
,y
,w
,h
),xmargin
,ymargin
).
- PySide2.QtWidgets.QGraphicsItem.extension(variant)¶
- Parameters:
variant – object
- Return type:
object
Note: This is provided as a hook to avoid future problems related to adding virtual functions.
- PySide2.QtWidgets.QGraphicsItem.filtersChildEvents()¶
- Return type:
bool
Returns
true
if this item filters child events (i.e., all events intended for any of its children are instead sent to this item); otherwise, false is returned.The default value is false; child events are not filtered.
See also
- PySide2.QtWidgets.QGraphicsItem.flags()¶
- Return type:
GraphicsItemFlags
Returns this item’s flags. The flags describe what configurable features of the item are enabled and not. For example, if the flags include
ItemIsFocusable
, the item can accept input focus.By default, no flags are enabled.
See also
- PySide2.QtWidgets.QGraphicsItem.focusInEvent(event)¶
- Parameters:
event –
PySide2.QtGui.QFocusEvent
This event handler, for event
event
, can be reimplemented to receive focus in events for this item. The default implementation callsensureVisible()
.See also
- PySide2.QtWidgets.QGraphicsItem.focusItem()¶
- Return type:
If this item, a child or descendant of this item currently has input focus, this function will return a pointer to that item. If no descendant has input focus,
None
is returned.See also
- PySide2.QtWidgets.QGraphicsItem.focusOutEvent(event)¶
- Parameters:
event –
PySide2.QtGui.QFocusEvent
This event handler, for event
event
, can be reimplemented to receive focus out events for this item. The default implementation does nothing.See also
- PySide2.QtWidgets.QGraphicsItem.focusProxy()¶
- Return type:
Returns this item’s focus proxy, or
None
if this item has no focus proxy.See also
- PySide2.QtWidgets.QGraphicsItem.focusScopeItem()¶
- Return type:
Returns this item’s focus scope item.
- PySide2.QtWidgets.QGraphicsItem.grabKeyboard()¶
Grabs the keyboard input.
The item will receive all keyboard input to the scene until one of the following events occur:
The item becomes invisible
The item is removed from the scene
The item is deleted
The item calls
ungrabKeyboard()
Another item calls ; the item will regain the keyboard grab when the other item calls
ungrabKeyboard()
.
When an item gains the keyboard grab, it receives a
GrabKeyboard
event. When it loses the keyboard grab, it receives aUngrabKeyboard
event. These events can be used to detect when your item gains or loses the keyboard grab through other means than gaining input focus.It is almost never necessary to explicitly grab the keyboard in Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the keyboard when your item gains input focus, and releases it when your item loses input focus, or when the item is hidden.
Note that only visible items can grab keyboard input. Calling on an invisible item has no effect.
Keyboard events are not affected.
See also
- PySide2.QtWidgets.QGraphicsItem.grabMouse()¶
Grabs the mouse input.
This item will receive all mouse events for the scene until any of the following events occurs:
The item becomes invisible
The item is removed from the scene
The item is deleted
The item call
ungrabMouse()
Another item calls ; the item will regain the mouse grab when the other item calls
ungrabMouse()
.
When an item gains the mouse grab, it receives a
GrabMouse
event. When it loses the mouse grab, it receives aUngrabMouse
event. These events can be used to detect when your item gains or loses the mouse grab through other means than receiving mouse button events.It is almost never necessary to explicitly grab the mouse in Qt, as Qt grabs and releases it sensibly. In particular, Qt grabs the mouse when you press a mouse button, and keeps the mouse grabbed until you release the last mouse button. Also,
Popup
widgets implicitly call when shown, andungrabMouse()
when hidden.Note that only visible items can grab mouse input. Calling on an invisible item has no effect.
Keyboard events are not affected.
- PySide2.QtWidgets.QGraphicsItem.graphicsEffect()¶
- Return type:
Returns a pointer to this item’s effect if it has one; otherwise
None
.See also
- PySide2.QtWidgets.QGraphicsItem.group()¶
- Return type:
Returns a pointer to this item’s item group, or
None
if this item is not member of a group.
- PySide2.QtWidgets.QGraphicsItem.handlesChildEvents()¶
- Return type:
bool
Returns
true
if this item handles child events (i.e., all events intended for any of its children are instead sent to this item); otherwise, false is returned.This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually.
The default is to return false; children handle their own events. The exception for this is if the item is a
QGraphicsItemGroup
, then it defaults to return true.See also
- PySide2.QtWidgets.QGraphicsItem.hasCursor()¶
- Return type:
bool
Returns
true
if this item has a cursor set; otherwise, false is returned.By default, items don’t have any cursor set.
cursor()
will return a standard pointing arrow cursor.See also
- PySide2.QtWidgets.QGraphicsItem.hasFocus()¶
- Return type:
bool
Returns
true
if this item is active, and it or itsfocus proxy
has keyboard input focus; otherwise, returnsfalse
.See also
- PySide2.QtWidgets.QGraphicsItem.hide()¶
Hides the item (items are visible by default).
This convenience function is equivalent to calling
setVisible(false)
.See also
- PySide2.QtWidgets.QGraphicsItem.hoverEnterEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive hover enter events for this item. The default implementation callsupdate()
; otherwise it does nothing.Calling
ignore()
oraccept()
onevent
has no effect.
- PySide2.QtWidgets.QGraphicsItem.hoverLeaveEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive hover leave events for this item. The default implementation callsupdate()
; otherwise it does nothing.Calling
ignore()
oraccept()
onevent
has no effect.
- PySide2.QtWidgets.QGraphicsItem.hoverMoveEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive hover move events for this item. The default implementation does nothing.Calling
ignore()
oraccept()
onevent
has no effect.
- PySide2.QtWidgets.QGraphicsItem.inputMethodEvent(event)¶
- Parameters:
event –
PySide2.QtGui.QInputMethodEvent
This event handler, for event
event
, can be reimplemented to receive input method events for this item. The default implementation ignores the event.See also
- PySide2.QtWidgets.QGraphicsItem.inputMethodHints()¶
- Return type:
InputMethodHints
Returns the current input method hints of this item.
Input method hints are only relevant for input items. The hints are used by the input method to indicate how it should operate. For example, if the Qt::ImhNumbersOnly flag is set, the input method may change its visual components to reflect that only numbers can be entered.
The effect may vary between input method implementations.
See also
- PySide2.QtWidgets.QGraphicsItem.inputMethodQuery(query)¶
- Parameters:
query –
InputMethodQuery
- Return type:
object
This method is only relevant for input items. It is used by the input method to query a set of properties of the item to be able to support complex input method operations, such as support for surrounding text and reconversions.
query
specifies which property is queried.See also
inputMethodEvent()
QInputMethodEvent
- PySide2.QtWidgets.QGraphicsItem.installSceneEventFilter(filterItem)¶
- Parameters:
filterItem –
PySide2.QtWidgets.QGraphicsItem
Installs an event filter for this item on
filterItem
, causing all events for this item to first pass throughfilterItem
‘ssceneEventFilter()
function.To filter another item’s events, install this item as an event filter for the other item. Example:
scene = QGraphicsScene() ellipse = scene.addEllipse(QRectF(-10, -10, 20, 20)) line = scene.addLine(QLineF(-10, -10, 20, 20)) line.installSceneEventFilter(ellipse) # line's events are filtered by ellipse's sceneEventFilter() function. ellipse.installSceneEventFilter(line) # ellipse's events are filtered by line's sceneEventFilter() function.
An item can only filter events for other items in the same scene. Also, an item cannot filter its own events; instead, you can reimplement
sceneEvent()
directly.Items must belong to a scene for scene event filters to be installed and used.
- PySide2.QtWidgets.QGraphicsItem.isActive()¶
- Return type:
bool
Returns
true
if this item is active; otherwise returnsfalse
.An item can only be active if the scene is active. An item is active if it is, or is a descendent of, an active panel. Items in non-active panels are not active.
Items that are not part of a panel follow scene activation when the scene has no active panel.
Only active items can gain input focus.
See also
- PySide2.QtWidgets.QGraphicsItem.isAncestorOf(child)¶
- Parameters:
child –
PySide2.QtWidgets.QGraphicsItem
- Return type:
bool
Returns
true
if this item is an ancestor ofchild
(i.e., if this item ischild
‘s parent, or one ofchild
‘s parent’s ancestors).See also
- PySide2.QtWidgets.QGraphicsItem.isBlockedByModalPanel()¶
- Return type:
(retval, blockingPanel)
Returns
true
if this item is blocked by a modal panel, false otherwise. IfblockingPanel
is non-zero,blockingPanel
will be set to the modal panel that is blocking this item. If this item is not blocked,blockingPanel
will not be set by this function.This function always returns
false
for items not in a scene.See also
panelModality()
setPanelModality()
PanelModality
- PySide2.QtWidgets.QGraphicsItem.isClipped()¶
- Return type:
bool
Returns
true
if this item is clipped. An item is clipped if it has either set theItemClipsToShape
flag, or if it or any of its ancestors has set theItemClipsChildrenToShape
flag.Clipping affects the item’s appearance (i.e., painting), as well as mouse and hover event delivery.
See also
- PySide2.QtWidgets.QGraphicsItem.isEnabled()¶
- Return type:
bool
Returns
true
if the item is enabled; otherwise, false is returned.See also
- PySide2.QtWidgets.QGraphicsItem.isObscured([rect=QRectF()])¶
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
bool
This is an overloaded function.
Returns
true
ifrect
is completely obscured by the opaque shape of any of colliding items above it (i.e., with a higher Z value than this item).See also
- PySide2.QtWidgets.QGraphicsItem.isObscured(x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
bool
This is an overloaded function.
This convenience function is equivalent to calling
isObscured
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.isObscuredBy(item)¶
- Parameters:
- Return type:
bool
Returns
true
if this item’s bounding rect is completely obscured by the opaque shape ofitem
.The base implementation maps
item
‘sopaqueArea()
to this item’s coordinate system, and then checks if this item’sboundingRect()
is fully contained within the mapped shape.You can reimplement this function to provide a custom algorithm for determining whether this item is obscured by
item
.See also
- PySide2.QtWidgets.QGraphicsItem.isPanel()¶
- Return type:
bool
Returns
true
if the item is a panel; otherwise returnsfalse
.See also
panel()
ItemIsPanel
- PySide2.QtWidgets.QGraphicsItem.isSelected()¶
- Return type:
bool
Returns
true
if this item is selected; otherwise, false is returned.Items that are in a group inherit the group’s selected state.
Items are not selected by default.
See also
- PySide2.QtWidgets.QGraphicsItem.isUnderMouse()¶
- Return type:
bool
Returns
true
if this item is currently under the mouse cursor in one of the views; otherwise, false is returned.See also
views()
pos()
- PySide2.QtWidgets.QGraphicsItem.isVisible()¶
- Return type:
bool
Returns
true
if the item is visible; otherwise, false is returned.Note that the item’s general visibility is unrelated to whether or not it is actually being visualized by a
QGraphicsView
.See also
- PySide2.QtWidgets.QGraphicsItem.isVisibleTo(parent)¶
- Parameters:
parent –
PySide2.QtWidgets.QGraphicsItem
- Return type:
bool
Returns
true
if the item is visible toparent
; otherwise, false is returned.parent
can beNone
, in which case this function will return whether the item is visible to the scene or not.An item may not be visible to its ancestors even if
isVisible()
is true. It may also be visible to its ancestors even ifisVisible()
is false. If any ancestor is hidden, the item itself will be implicitly hidden, in which case this function will return false.See also
- PySide2.QtWidgets.QGraphicsItem.isWidget()¶
- Return type:
bool
Returns
true
if this item is a widget (i.e., QGraphicsWidget ); otherwise, returnsfalse
.
- PySide2.QtWidgets.QGraphicsItem.isWindow()¶
- Return type:
bool
Returns
true
if the item is a QGraphicsWidget window, otherwise returns false.See also
- PySide2.QtWidgets.QGraphicsItem.itemChange(change, value)¶
- Parameters:
change –
GraphicsItemChange
value – object
- Return type:
object
This virtual function is called by
QGraphicsItem
to notify custom items that some part of the item’s state changes. By reimplementing this function, you can react to a change, and in some cases (depending onchange
), adjustments can be made.change
is the parameter of the item that is changing.value
is the new value; the type of the value depends onchange
.Example:
def itemChange(self, change, value): if change == ItemPositionChange && scene(): # value is the new position. rect = scene().sceneRect() if !rect.contains(value): # Keep the item inside the scene rect. value.setX(qMin(rect.right(), qMax(value.x(), rect.left()))) value.setY(qMin(rect.bottom(), qMax(value.y(), rect.top()))) return value return QGraphicsItem.itemChange(self, change, value)
The default implementation does nothing, and returns
value
.Note: Certain
QGraphicsItem
functions cannot be called in a reimplementation of this function; see theGraphicsItemChange
documentation for details.See also
GraphicsItemChange
- PySide2.QtWidgets.QGraphicsItem.itemTransform(other)¶
- Parameters:
other –
PySide2.QtWidgets.QGraphicsItem
- Return type:
(QTransform, bool ok)
Returns a
QTransform
that maps coordinates from this item toother
. Ifok
is not null, and if there is no such transform, the boolean pointed to byok
will be set to false; otherwise it will be set to true.This transform provides an alternative to the
mapToItem()
ormapFromItem()
functions, by returning the appropriate transform so that you can map shapes and coordinates yourself. It also helps you write more efficient code when repeatedly mapping between the same two items.Note
In rare circumstances, there is no transform that maps between two items.
See also
- PySide2.QtWidgets.QGraphicsItem.keyPressEvent(event)¶
- Parameters:
event –
PySide2.QtGui.QKeyEvent
This event handler, for event
event
, can be reimplemented to receive key press events for this item. The default implementation ignores the event. If you reimplement this handler, the event will by default be accepted.Note that key events are only received for items that set the
ItemIsFocusable
flag, and that have keyboard input focus.
- PySide2.QtWidgets.QGraphicsItem.keyReleaseEvent(event)¶
- Parameters:
event –
PySide2.QtGui.QKeyEvent
This event handler, for event
event
, can be reimplemented to receive key release events for this item. The default implementation ignores the event. If you reimplement this handler, the event will by default be accepted.Note that key events are only received for items that set the
ItemIsFocusable
flag, and that have keyboard input focus.
- PySide2.QtWidgets.QGraphicsItem.mapFromItem(item, path)¶
- Parameters:
path –
PySide2.QtGui.QPainterPath
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromItem(item, point)
- Parameters:
point –
PySide2.QtCore.QPointF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromItem(item, polygon)
- Parameters:
polygon –
PySide2.QtGui.QPolygonF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromItem(item, rect)
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromItem(item, x, y)
- Parameters:
x – float
y – float
- Return type:
This is an overloaded function.
This convenience function is equivalent to calling
mapFromItem
(item
,QPointF
(x
,y
)).
- PySide2.QtWidgets.QGraphicsItem.mapFromItem(item, x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapFromItem
(item,QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapFromParent(x, y, w, h)¶
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapFromItem
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapFromParent(point)
- Parameters:
point –
PySide2.QtCore.QPointF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromParent(x, y)
- Parameters:
x – float
y – float
- Return type:
This is an overloaded function.
This convenience function is equivalent to calling
mapFromParent
(QPointF
(x
,y
)).
- PySide2.QtWidgets.QGraphicsItem.mapFromParent(polygon)
- Parameters:
polygon –
PySide2.QtGui.QPolygonF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromParent(path)
- Parameters:
path –
PySide2.QtGui.QPainterPath
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromParent(rect)
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromScene(path)¶
- Parameters:
path –
PySide2.QtGui.QPainterPath
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromScene(point)
- Parameters:
point –
PySide2.QtCore.QPointF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromScene(polygon)
- Parameters:
polygon –
PySide2.QtGui.QPolygonF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromScene(rect)
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapFromScene(x, y)
- Parameters:
x – float
y – float
- Return type:
This is an overloaded function.
This convenience function is equivalent to calling
mapFromScene
(QPointF
(x
,y
)).
- PySide2.QtWidgets.QGraphicsItem.mapFromScene(x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapFromScene
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapRectFromItem(item, rect)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
Maps the rectangle
rect
, which is initem
‘s coordinate system, to this item’s coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).If
item
isNone
, this function returns the same asmapRectFromScene()
.
- PySide2.QtWidgets.QGraphicsItem.mapRectFromItem(item, x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapRectFromItem
(item,QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapRectFromParent(x, y, w, h)¶
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapRectFromParent
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapRectFromParent(rect)
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
Maps the rectangle
rect
, which is in this item’s parent’s coordinate system, to this item’s coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).
- PySide2.QtWidgets.QGraphicsItem.mapRectFromScene(rect)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
Maps the rectangle
rect
, which is in scene coordinates, to this item’s coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).
- PySide2.QtWidgets.QGraphicsItem.mapRectFromScene(x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapRectFromScene
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapRectToItem(item, rect)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
Maps the rectangle
rect
, which is in this item’s coordinate system, toitem
‘s coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).If
item
isNone
, this function returns the same asmapRectToScene()
.
- PySide2.QtWidgets.QGraphicsItem.mapRectToItem(item, x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapRectToItem
(item,QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapRectToParent(rect)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
Maps the rectangle
rect
, which is in this item’s coordinate system, to its parent’s coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).
- PySide2.QtWidgets.QGraphicsItem.mapRectToParent(x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapRectToParent
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapRectToScene(rect)¶
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
Maps the rectangle
rect
, which is in this item’s coordinate system, to the scene coordinate system, and returns the mapped rectangle as a new rectangle (i.e., the bounding rectangle of the resulting polygon).
- PySide2.QtWidgets.QGraphicsItem.mapRectToScene(x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapRectToScene
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapToItem(item, x, y, w, h)¶
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapToItem
(item,QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapToItem(item, x, y)
- Parameters:
x – float
y – float
- Return type:
This is an overloaded function.
This convenience function is equivalent to calling
mapToItem
(item
,QPointF
(x
,y
)).
- PySide2.QtWidgets.QGraphicsItem.mapToItem(item, rect)
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToItem(item, point)
- Parameters:
point –
PySide2.QtCore.QPointF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToItem(item, polygon)
- Parameters:
polygon –
PySide2.QtGui.QPolygonF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToItem(item, path)
- Parameters:
path –
PySide2.QtGui.QPainterPath
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToParent(path)¶
- Parameters:
path –
PySide2.QtGui.QPainterPath
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToParent(x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapToParent
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.mapToParent(x, y)
- Parameters:
x – float
y – float
- Return type:
This is an overloaded function.
This convenience function is equivalent to calling
mapToParent
(QPointF
(x
,y
)).
- PySide2.QtWidgets.QGraphicsItem.mapToParent(polygon)
- Parameters:
polygon –
PySide2.QtGui.QPolygonF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToParent(point)
- Parameters:
point –
PySide2.QtCore.QPointF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToParent(rect)
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToScene(path)¶
- Parameters:
path –
PySide2.QtGui.QPainterPath
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToScene(point)
- Parameters:
point –
PySide2.QtCore.QPointF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToScene(polygon)
- Parameters:
polygon –
PySide2.QtGui.QPolygonF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToScene(rect)
- Parameters:
rect –
PySide2.QtCore.QRectF
- Return type:
- PySide2.QtWidgets.QGraphicsItem.mapToScene(x, y)
- Parameters:
x – float
y – float
- Return type:
This is an overloaded function.
This convenience function is equivalent to calling
mapToScene
(QPointF
(x
,y
)).
- PySide2.QtWidgets.QGraphicsItem.mapToScene(x, y, w, h)
- Parameters:
x – float
y – float
w – float
h – float
- Return type:
This convenience function is equivalent to calling
mapToScene
(QRectF
(x
,y
,w
,h
)).
- PySide2.QtWidgets.QGraphicsItem.matrix()¶
- Return type:
Note
This function is deprecated.
Returns the item’s affine transformation matrix. This is a subset or the item’s full transformation matrix, and might not represent the item’s full transformation.
Use
transform()
instead.See also
- PySide2.QtWidgets.QGraphicsItem.mouseDoubleClickEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive mouse double-click events for this item.When doubleclicking an item, the item will first receive a mouse press event, followed by a release event (i.e., a click), then a double-click event, and finally a release event.
Calling
ignore()
oraccept()
onevent
has no effect.The default implementation calls
mousePressEvent()
. If you want to keep the base implementation when reimplementing this function, call in your reimplementation.Note that an item will not receive double click events if it is neither
selectable
normovable
(single mouse clicks are ignored in this case, and that stops the generation of double clicks).
- PySide2.QtWidgets.QGraphicsItem.mouseMoveEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive mouse move events for this item. If you do receive this event, you can be certain that this item also received a mouse press event, and that this item is the current mouse grabber.Calling
ignore()
oraccept()
onevent
has no effect.The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call in your reimplementation.
Please note that
mousePressEvent()
decides which graphics item it is that receives mouse events. See themousePressEvent()
description for details.
- PySide2.QtWidgets.QGraphicsItem.mousePressEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive mouse press events for this item. Mouse press events are only delivered to items that accept the mouse button that is pressed. By default, an item accepts all mouse buttons, but you can change this by callingsetAcceptedMouseButtons()
.The mouse press event decides which item should become the mouse grabber (see
mouseGrabberItem()
). If you do not reimplement this function, the press event will propagate to any topmost item beneath this item, and no other mouse events will be delivered to this item.If you do reimplement this function,
event
will by default be accepted (seeaccept()
), and this item is then the mouse grabber. This allows the item to receive future move, release and double-click events. If you callignore()
onevent
, this item will lose the mouse grab, andevent
will propagate to any topmost item beneath. No further mouse events will be delivered to this item unless a new mouse press event is received.The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call in your reimplementation.
The event is
ignore()
d for items that are neithermovable
norselectable
.
- PySide2.QtWidgets.QGraphicsItem.mouseReleaseEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive mouse release events for this item.Calling
ignore()
oraccept()
onevent
has no effect.The default implementation handles basic item interaction, such as selection and moving. If you want to keep the base implementation when reimplementing this function, call in your reimplementation.
Please note that
mousePressEvent()
decides which graphics item it is that receives mouse events. See themousePressEvent()
description for details.
- PySide2.QtWidgets.QGraphicsItem.moveBy(dx, dy)¶
- Parameters:
dx – float
dy – float
Moves the item by
dx
points horizontally, anddy
point vertically. This function is equivalent to callingsetPos
(pos()
+QPointF
(dx
,dy
)).
- PySide2.QtWidgets.QGraphicsItem.opacity()¶
- Return type:
float
Returns this item’s local opacity, which is between 0.0 (transparent) and 1.0 (opaque). This value is combined with parent and ancestor values into the
effectiveOpacity()
. The effective opacity decides how the item is rendered and also affects its visibility when queried by functions such asitems()
.The opacity property decides the state of the painter passed to the
paint()
function. If the item is cached, i.e.,ItemCoordinateCache
orDeviceCoordinateCache
, the effective property will be applied to the item’s cache as it is rendered.The default opacity is 1.0; fully opaque.
See also
setOpacity()
paint()
ItemIgnoresParentOpacity
ItemDoesntPropagateOpacityToChildren
- PySide2.QtWidgets.QGraphicsItem.opaqueArea()¶
- Return type:
This virtual function returns a shape representing the area where this item is opaque. An area is opaque if it is filled using an opaque brush or color (i.e., not transparent).
This function is used by
isObscuredBy()
, which is called by underlying items to determine if they are obscured by this item.The default implementation returns an empty
QPainterPath
, indicating that this item is completely transparent and does not obscure any other items.See also
- PySide2.QtWidgets.QGraphicsItem.paint(painter, option[, widget=None])¶
- Parameters:
painter –
PySide2.QtGui.QPainter
widget –
PySide2.QtWidgets.QWidget
This function, which is usually called by
QGraphicsView
, paints the contents of an item in local coordinates.Reimplement this function in a
QGraphicsItem
subclass to provide the item’s painting implementation, usingpainter
. Theoption
parameter provides style options for the item, such as its state, exposed area and its level-of-detail hints. Thewidget
argument is optional. If provided, it points to the widget that is being painted on; otherwise, it is 0. For cached painting,widget
is always 0.def paint(self, painter, option, widget): painter.drawRoundedRect(-10, -10, 20, 20, 5, 5)
The painter’s pen is 0-width by default, and its pen is initialized to the
Text
brush from the paint device’s palette. The brush is initialized toWindow
.Make sure to constrain all painting inside the boundaries of
boundingRect()
to avoid rendering artifacts (asQGraphicsView
does not clip the painter for you). In particular, whenQPainter
renders the outline of a shape using an assignedQPen
, half of the outline will be drawn outside, and half inside, the shape you’re rendering (e.g., with a pen width of 2 units, you must draw outlines 1 unit insideboundingRect()
).QGraphicsItem
does not support use of cosmetic pens with a non-zero width.All painting is done in local coordinates.
Note
It is mandatory that an item will always redraw itself in the exact same way, unless
update()
was called; otherwise visual artifacts may occur. In other words, two subsequent calls to must always produce the same output, unlessupdate()
was called between them.Note
Enabling caching for an item does not guarantee that will be invoked only once by the Graphics View framework, even without any explicit call to
update()
. See the documentation ofsetCacheMode()
for more details.See also
setCacheMode()
width()
Item CoordinatesItemUsesExtendedStyleOption
- PySide2.QtWidgets.QGraphicsItem.panel()¶
- Return type:
Returns the item’s panel, or
None
if this item does not have a panel. If the item is a panel, it will return itself. Otherwise it will return the closest ancestor that is a panel.See also
isPanel()
ItemIsPanel
- PySide2.QtWidgets.QGraphicsItem.panelModality()¶
- Return type:
Returns the modality for this item.
See also
- PySide2.QtWidgets.QGraphicsItem.parentItem()¶
- Return type:
Returns a pointer to this item’s parent item. If this item does not have a parent,
None
is returned.See also
- PySide2.QtWidgets.QGraphicsItem.parentObject()¶
- Return type:
Returns a pointer to the item’s parent, cast to a
QGraphicsObject
. ReturnsNone
if the parent item is not aQGraphicsObject
.See also
- PySide2.QtWidgets.QGraphicsItem.parentWidget()¶
- Return type:
Returns a pointer to the item’s parent widget. The item’s parent widget is the closest parent item that is a widget.
See also
- PySide2.QtWidgets.QGraphicsItem.pos()¶
- Return type:
Returns the position of the item in parent coordinates. If the item has no parent, its position is given in scene coordinates.
The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates; this function returns the same as
mapToParent
(0, 0).For convenience, you can also call
scenePos()
to determine the item’s position in scene coordinates, regardless of its parent.
- PySide2.QtWidgets.QGraphicsItem.prepareGeometryChange()¶
Prepares the item for a geometry change. Call this function before changing the bounding rect of an item to keep
QGraphicsScene
‘s index up to date.will call
update()
if this is necessary.Example:
def setRadius(self, newRadius): if radius != newRadius: prepareGeometryChange() radius = newRadius
See also
- PySide2.QtWidgets.QGraphicsItem.removeFromIndex()¶
Removes this item from the scene’s index. Called in conjunction with to ensure the index bookkeeping is correct when the item’s position, transformation or shape changes.
- PySide2.QtWidgets.QGraphicsItem.removeSceneEventFilter(filterItem)¶
- Parameters:
filterItem –
PySide2.QtWidgets.QGraphicsItem
Removes an event filter on this item from
filterItem
.See also
- PySide2.QtWidgets.QGraphicsItem.resetMatrix()¶
Note
This function is deprecated.
Use
resetTransform()
instead.
- PySide2.QtWidgets.QGraphicsItem.resetTransform()¶
Resets this item’s transformation matrix to the identity matrix or all the transformation properties to their default values. This is equivalent to calling
setTransform(QTransform())
.See also
- PySide2.QtWidgets.QGraphicsItem.rotation()¶
- Return type:
float
Returns the clockwise rotation, in degrees, around the Z axis. The default value is 0 (i.e., the item is not rotated).
The rotation is combined with the item’s
scale()
,transform()
andtransformations()
to map the item’s coordinate system to the parent item.See also
setRotation()
transformOriginPoint()
Transformations
- PySide2.QtWidgets.QGraphicsItem.scale()¶
- Return type:
float
Returns the scale factor of the item. The default scale factor is 1.0 (i.e., the item is not scaled).
The scale is combined with the item’s
rotation()
,transform()
andtransformations()
to map the item’s coordinate system to the parent item.See also
setScale()
rotation()
Transformations
- PySide2.QtWidgets.QGraphicsItem.scene()¶
- Return type:
Returns the current scene for the item, or
None
if the item is not stored in a scene.To add or move an item to a scene, call
addItem()
.
- PySide2.QtWidgets.QGraphicsItem.sceneBoundingRect()¶
- Return type:
Returns the bounding rect of this item in scene coordinates, by combining
sceneTransform()
withboundingRect()
.
- PySide2.QtWidgets.QGraphicsItem.sceneEvent(event)¶
- Parameters:
event –
PySide2.QtCore.QEvent
- Return type:
bool
This virtual function receives events to this item. Reimplement this function to intercept events before they are dispatched to the specialized event handlers
contextMenuEvent()
,focusInEvent()
,focusOutEvent()
,hoverEnterEvent()
,hoverMoveEvent()
,hoverLeaveEvent()
,keyPressEvent()
,keyReleaseEvent()
,mousePressEvent()
,mouseReleaseEvent()
,mouseMoveEvent()
, andmouseDoubleClickEvent()
.Returns
true
if the event was recognized and handled; otherwise, (e.g., if the event type was not recognized,) false is returned.event
is the intercepted event.
- PySide2.QtWidgets.QGraphicsItem.sceneEventFilter(watched, event)¶
- Parameters:
watched –
PySide2.QtWidgets.QGraphicsItem
event –
PySide2.QtCore.QEvent
- Return type:
bool
Filters events for the item
watched
.event
is the filtered event.Reimplementing this function in a subclass makes it possible for the item to be used as an event filter for other items, intercepting all the events sent to those items before they are able to respond.
Reimplementations must return true to prevent further processing of a given event, ensuring that it will not be delivered to the watched item, or return false to indicate that the event should be propagated further by the event system.
See also
- PySide2.QtWidgets.QGraphicsItem.sceneMatrix()¶
- Return type:
Note
This function is deprecated.
Use
sceneTransform()
instead.
- PySide2.QtWidgets.QGraphicsItem.scenePos()¶
- Return type:
Returns the item’s position in scene coordinates. This is equivalent to calling
mapToScene(0, 0)
.
- PySide2.QtWidgets.QGraphicsItem.sceneTransform()¶
- Return type:
Returns this item’s scene transformation matrix. This matrix can be used to map coordinates and geometrical shapes from this item’s local coordinate system to the scene’s coordinate system. To map coordinates from the scene, you must first invert the returned matrix.
Example:
rect = QGraphicsRectItem() rect.setPos(100, 100) rect.sceneTransform().map(QPointF(0, 0)) # returns QPointF(100, 100) rect.sceneTransform().inverted().map(QPointF(100, 100)) # returns QPointF(0, 0);
Unlike
transform()
, which returns only an item’s local transformation, this function includes the item’s (and any parents’) position, and all the transformation properties.See also
transform()
setTransform()
scenePos()
The Graphics View Coordinate SystemTransformations
- PySide2.QtWidgets.QGraphicsItem.setAcceptDrops(on)¶
- Parameters:
on – bool
If
on
is true, this item will accept drag and drop events; otherwise, it is transparent for drag and drop events. By default, items do not accept drag and drop events.See also
- PySide2.QtWidgets.QGraphicsItem.setAcceptHoverEvents(enabled)¶
- Parameters:
enabled – bool
If
enabled
is true, this item will accept hover events; otherwise, it will ignore them. By default, items do not accept hover events.Hover events are delivered when there is no current mouse grabber item. They are sent when the mouse cursor enters an item, when it moves around inside the item, and when the cursor leaves an item. Hover events are commonly used to highlight an item when it’s entered, and for tracking the mouse cursor as it hovers over the item (equivalent to
mouseTracking
).Parent items receive hover enter events before their children, and leave events after their children. The parent does not receive a hover leave event if the cursor enters a child, though; the parent stays “hovered” until the cursor leaves its area, including its children’s areas.
If a parent item handles child events, it will receive hover move, drag move, and drop events as the cursor passes through its children, but it does not receive hover enter and hover leave, nor drag enter and drag leave events on behalf of its children.
A QGraphicsWidget with window decorations will accept hover events regardless of the value of
acceptHoverEvents()
.
- PySide2.QtWidgets.QGraphicsItem.setAcceptTouchEvents(enabled)¶
- Parameters:
enabled – bool
If
enabled
is true, this item will accepttouch events
; otherwise, it will ignore them. By default, items do not accept touch events.See also
- PySide2.QtWidgets.QGraphicsItem.setAcceptedMouseButtons(buttons)¶
- Parameters:
buttons –
MouseButtons
Sets the mouse
buttons
that this item accepts mouse events for.By default, all mouse buttons are accepted. If an item accepts a mouse button, it will become the mouse grabber item when a mouse press event is delivered for that button. However, if the item does not accept the mouse button,
QGraphicsScene
will forward the mouse events to the first item beneath it that does.To disable mouse events for an item (i.e., make it transparent for mouse events), call (0).
See also
- PySide2.QtWidgets.QGraphicsItem.setActive(active)¶
- Parameters:
active – bool
If
active
is true, and the scene is active, this item’s panel will be activated. Otherwise, the panel is deactivated.If the item is not part of an active scene,
active
will decide what happens to the panel when the scene becomes active or the item is added to the scene. If true, the item’s panel will be activated when the item is either added to the scene or the scene is activated. Otherwise, the item will stay inactive independent of the scene’s activated state.See also
- PySide2.QtWidgets.QGraphicsItem.setBoundingRegionGranularity(granularity)¶
- Parameters:
granularity – float
Sets the bounding region granularity to
granularity
; a value between and including 0 and 1. The default value is 0 (i.e., the lowest granularity, where the bounding region corresponds to the item’s bounding rectangle).The granularity is used by
boundingRegion()
to calculate how fine the bounding region of the item should be. The highest achievable granularity is 1, whereboundingRegion()
will return the finest outline possible for the respective device (e.g., for aQGraphicsView
viewport, this gives you a pixel-perfect bounding region). The lowest possible granularity is 0. The value ofgranularity
describes the ratio between device resolution and the resolution of the bounding region (e.g., a value of 0.25 will provide a region where each chunk corresponds to 4x4 device units / pixels).See also
- PySide2.QtWidgets.QGraphicsItem.setCacheMode(mode[, cacheSize=QSize()])¶
- Parameters:
mode –
CacheMode
cacheSize –
PySide2.QtCore.QSize
Sets the item’s cache mode to
mode
.The optional
logicalCacheSize
argument is used only byItemCoordinateCache
mode, and describes the resolution of the cache buffer; iflogicalCacheSize
is (100, 100),QGraphicsItem
will fit the item into 100x100 pixels in graphics memory, regardless of the logical size of the item itself. By defaultQGraphicsItem
uses the size ofboundingRect()
. For all other cache modes thanItemCoordinateCache
,logicalCacheSize
is ignored.Caching can speed up rendering if your item spends a significant time redrawing itself. In some cases the cache can also slow down rendering, in particular when the item spends less time redrawing than
QGraphicsItem
spends redrawing from the cache.When caching is enabled, an item’s
paint()
function will generally draw into an offscreen pixmap cache; for any subsequent repaint requests, the Graphics View framework will redraw from the cache. This approach works particularly well withQGLWidget
, which stores all the cache as OpenGL textures.Be aware that
QPixmapCache
‘s cache limit may need to be changed to obtain optimal performance.You can read more about the different cache modes in the
CacheMode
documentation.Note
Enabling caching does not imply that the item’s
paint()
function will be called only in response to an explicitupdate()
call. For instance, under memory pressure, Qt may decide to drop some of the cache information; in such cases an item’spaint()
function will be called even if there was noupdate()
call (that is, exactly as if there were no caching enabled).See also
cacheMode()
CacheMode
setCacheLimit()
- PySide2.QtWidgets.QGraphicsItem.setCursor(cursor)¶
- Parameters:
cursor –
PySide2.QtGui.QCursor
Sets the current cursor shape for the item to
cursor
. The mouse cursor will assume this shape when it’s over this item. See thelist of predefined cursor objects
for a range of useful shapes.An editor item might want to use an I-beam cursor:
item.setCursor(Qt.IBeamCursor)
If no cursor has been set, the cursor of the item beneath is used.
See also
cursor()
hasCursor()
unsetCursor()
cursor
overrideCursor()
- PySide2.QtWidgets.QGraphicsItem.setData(key, value)¶
- Parameters:
key – int
value – object
Sets this item’s custom data for the key
key
tovalue
.Custom item data is useful for storing arbitrary properties for any item. Qt does not use this feature for storing data; it is provided solely for the convenience of the user.
See also
- PySide2.QtWidgets.QGraphicsItem.setEnabled(enabled)¶
- Parameters:
enabled – bool
If
enabled
is true, the item is enabled; otherwise, it is disabled.Disabled items are visible, but they do not receive any events, and cannot take focus nor be selected. Mouse events are discarded; they are not propagated unless the item is also invisible, or if it does not accept mouse events (see
acceptedMouseButtons()
). A disabled item cannot become the mouse grabber, and as a result of this, an item loses the grab if it becomes disabled when grabbing the mouse, just like it loses focus if it had focus when it was disabled.Disabled items are traditionally drawn using grayed-out colors (see
Disabled
).If you disable a parent item, all its children will also be disabled. If you enable a parent item, all children will be enabled, unless they have been explicitly disabled (i.e., if you call (false) on a child, it will not be re-enabled if its parent is disabled, and then enabled again).
Items are enabled by default.
Note
If you install an event filter, you can still intercept events before they are delivered to items; this mechanism disregards the item’s enabled state.
See also
- PySide2.QtWidgets.QGraphicsItem.setFiltersChildEvents(enabled)¶
- Parameters:
enabled – bool
If
enabled
is true, this item is set to filter all events for all its children (i.e., all events intented for any of its children are instead sent to this item); otherwise, ifenabled
is false, this item will only handle its own events. The default value is false.See also
- PySide2.QtWidgets.QGraphicsItem.setFlag(flag[, enabled=true])¶
- Parameters:
flag –
GraphicsItemFlag
enabled – bool
If
enabled
is true, the item flagflag
is enabled; otherwise, it is disabled.See also
- PySide2.QtWidgets.QGraphicsItem.setFlags(flags)¶
- Parameters:
flags –
GraphicsItemFlags
Sets the item flags to
flags
. All flags inflags
are enabled; all flags not inflags
are disabled.If the item had focus and
flags
does not enableItemIsFocusable
, the item loses focus as a result of calling this function. Similarly, if the item was selected, andflags
does not enabledItemIsSelectable
, the item is automatically unselected.By default, no flags are enabled. ( QGraphicsWidget enables the
ItemSendsGeometryChanges
flag by default in order to track position changes.)
- PySide2.QtWidgets.QGraphicsItem.setFocus([focusReason=Qt.OtherFocusReason])¶
- Parameters:
focusReason –
FocusReason
Gives keyboard input focus to this item. The
focusReason
argument will be passed into anyfocus event
generated by this function; it is used to give an explanation of what caused the item to get focus.Only enabled items that set the
ItemIsFocusable
flag can accept keyboard focus.If this item is not visible, not active, or not associated with a scene, it will not gain immediate input focus. However, it will be registered as the preferred focus item for its subtree of items, should it later become visible.
As a result of calling this function, this item will receive a
focus in event
withfocusReason
. If another item already has focus, that item will first receive afocus out event
indicating that it has lost input focus.See also
- PySide2.QtWidgets.QGraphicsItem.setFocusProxy(item)¶
- Parameters:
Sets the item’s focus proxy to
item
.If an item has a focus proxy, the focus proxy will receive input focus when the item gains input focus. The item itself will still have focus (i.e.,
hasFocus()
will return true), but only the focus proxy will receive the keyboard input.A focus proxy can itself have a focus proxy, and so on. In such case, keyboard input will be handled by the outermost focus proxy.
The focus proxy
item
must belong to the same scene as this item.See also
- PySide2.QtWidgets.QGraphicsItem.setGraphicsEffect(effect)¶
- Parameters:
effect –
PySide2.QtWidgets.QGraphicsEffect
Sets
effect
as the item’s effect. If there already is an effect installed on this item,QGraphicsItem
will delete the existing effect before installing the neweffect
. You can delete an existing effect by calling (None
).If
effect
is the installed effect on a different item, will remove the effect from the item and install it on this item.QGraphicsItem
takes ownership ofeffect
.Note
This function will apply the effect on itself and all its children.
See also
- PySide2.QtWidgets.QGraphicsItem.setGroup(group)¶
- Parameters:
Adds this item to the item group
group
. Ifgroup
isNone
, this item is removed from any current group and added as a child of the previous group’s parent.See also
- PySide2.QtWidgets.QGraphicsItem.setHandlesChildEvents(enabled)¶
- Parameters:
enabled – bool
If
enabled
is true, this item is set to handle all events for all its children (i.e., all events intented for any of its children are instead sent to this item); otherwise, ifenabled
is false, this item will only handle its own events. The default value is false.This property is useful for item groups; it allows one item to handle events on behalf of its children, as opposed to its children handling their events individually.
If a child item accepts hover events, its parent will receive hover move events as the cursor passes through the child, but it does not receive hover enter and hover leave events on behalf of its child.
See also
- PySide2.QtWidgets.QGraphicsItem.setInputMethodHints(hints)¶
- Parameters:
hints –
InputMethodHints
Sets the current input method hints of this item to
hints
.See also
- PySide2.QtWidgets.QGraphicsItem.setMatrix(matrix[, combine=false])¶
- Parameters:
matrix –
PySide2.QtGui.QMatrix
combine – bool
Note
This function is deprecated.
Sets the item’s affine transformation matrix. This is a subset or the item’s full transformation matrix, and might not represent the item’s full transformation.
Use
setTransform()
instead.
- PySide2.QtWidgets.QGraphicsItem.setOpacity(opacity)¶
- Parameters:
opacity – float
Sets this item’s local
opacity
, between 0.0 (transparent) and 1.0 (opaque). The item’s local opacity is combined with parent and ancestor opacities into theeffectiveOpacity()
.By default, opacity propagates from parent to child, so if a parent’s opacity is 0.5 and the child is also 0.5, the child’s effective opacity will be 0.25.
The opacity property decides the state of the painter passed to the
paint()
function. If the item is cached, i.e.,ItemCoordinateCache
orDeviceCoordinateCache
, the effective property will be applied to the item’s cache as it is rendered.There are two item flags that affect how the item’s opacity is combined with the parent:
ItemIgnoresParentOpacity
andItemDoesntPropagateOpacityToChildren
.Note
Setting the opacity of an item to 0 will not make the item invisible (according to
isVisible()
), but the item will be treated like an invisible one. See the documentation ofsetVisible()
for more information.See also
- PySide2.QtWidgets.QGraphicsItem.setPanelModality(panelModality)¶
- Parameters:
panelModality –
PanelModality
Sets the modality for this item to
panelModality
.Changing the modality of a visible item takes effect immediately.
See also
- PySide2.QtWidgets.QGraphicsItem.setParentItem(parent)¶
- Parameters:
parent –
PySide2.QtWidgets.QGraphicsItem
Sets this item’s parent item to
newParent
. If this item already has a parent, it is first removed from the previous parent. IfnewParent
is 0, this item will become a top-level item.Note that this implicitly adds this graphics item to the scene of the parent. You should not
add
the item to the scene yourself.The behavior when calling this function on an item that is an ancestor of
newParent
is undefined.See also
- PySide2.QtWidgets.QGraphicsItem.setPos(pos)¶
- Parameters:
pos –
PySide2.QtCore.QPointF
Sets the position of the item to
pos
, which is in parent coordinates. For items with no parent,pos
is in scene coordinates.The position of the item describes its origin (local coordinate (0, 0)) in parent coordinates.
- PySide2.QtWidgets.QGraphicsItem.setPos(x, y)
- Parameters:
x – float
y – float
This is an overloaded function.
This convenience function is equivalent to calling
setPos
(QPointF
(x
,y
)).
- PySide2.QtWidgets.QGraphicsItem.setRotation(angle)¶
- Parameters:
angle – float
Sets the clockwise rotation
angle
, in degrees, around the Z axis. The default value is 0 (i.e., the item is not rotated). Assigning a negative value will rotate the item counter-clockwise. Normally the rotation angle is in the range (-360, 360), but it’s also possible to assign values outside of this range (e.g., a rotation of 370 degrees is the same as a rotation of 10 degrees).The item is rotated around its transform origin point, which by default is (0, 0). You can select a different transformation origin by calling
setTransformOriginPoint()
.The rotation is combined with the item’s
scale()
,transform()
andtransformations()
to map the item’s coordinate system to the parent item.See also
rotation()
setTransformOriginPoint()
Transformations
- PySide2.QtWidgets.QGraphicsItem.setScale(scale)¶
- Parameters:
scale – float
Sets the scale
factor
of the item. The default scale factor is 1.0 (i.e., the item is not scaled). A scale factor of 0.0 will collapse the item to a single point. If you provide a negative scale factor, the item will be flipped and mirrored (i.e., rotated 180 degrees).The item is scaled around its transform origin point, which by default is (0, 0). You can select a different transformation origin by calling
setTransformOriginPoint()
.The scale is combined with the item’s
rotation()
,transform()
andtransformations()
to map the item’s coordinate system to the parent item.
- PySide2.QtWidgets.QGraphicsItem.setSelected(selected)¶
- Parameters:
selected – bool
If
selected
is true and this item is selectable, this item is selected; otherwise, it is unselected.If the item is in a group, the whole group’s selected state is toggled by this function. If the group is selected, all items in the group are also selected, and if the group is not selected, no item in the group is selected.
Only visible, enabled, selectable items can be selected. If
selected
is true and this item is either invisible or disabled or unselectable, this function does nothing.By default, items cannot be selected. To enable selection, set the
ItemIsSelectable
flag.This function is provided for convenience, allowing individual toggling of the selected state of an item. However, a more common way of selecting items is to call
setSelectionArea()
, which will call this function for all visible, enabled, and selectable items within a specified area on the scene.See also
- PySide2.QtWidgets.QGraphicsItem.setToolTip(toolTip)¶
- Parameters:
toolTip – str
Sets the item’s tool tip to
toolTip
. IftoolTip
is empty, the item’s tool tip is cleared.
- PySide2.QtWidgets.QGraphicsItem.setTransform(matrix[, combine=false])¶
- Parameters:
matrix –
PySide2.QtGui.QTransform
combine – bool
Sets the item’s current transformation matrix to
matrix
.If
combine
is true, thenmatrix
is combined with the current matrix; otherwise,matrix
replaces the current matrix.combine
is false by default.To simplify interaction with items using a transformed view,
QGraphicsItem
provides mapTo… and mapFrom… functions that can translate between items’ and the scene’s coordinates. For example, you can callmapToScene()
to map an item coordinate to a scene coordinate, ormapFromScene()
to map from scene coordinates to item coordinates.The transformation matrix is combined with the item’s
rotation()
,scale()
andtransformations()
into a combined transformation that maps the item’s coordinate system to its parent.See also
transform()
setRotation()
setScale()
setTransformOriginPoint()
The Graphics View Coordinate SystemTransformations
- PySide2.QtWidgets.QGraphicsItem.setTransformOriginPoint(origin)¶
- Parameters:
origin –
PySide2.QtCore.QPointF
Sets the
origin
point for the transformation in item coordinates.See also
transformOriginPoint()
Transformations
- PySide2.QtWidgets.QGraphicsItem.setTransformOriginPoint(ax, ay)
- Parameters:
ax – float
ay – float
This is an overloaded function.
Sets the origin point for the transformation in item coordinates. This is equivalent to calling
setTransformOriginPoint
(QPointF
(x
,y
)).See also
setTransformOriginPoint()
Transformations
- PySide2.QtWidgets.QGraphicsItem.setTransformations(transformations)¶
- Parameters:
transformations –
Sets a list of graphics
transformations
(QGraphicsTransform
) that currently apply to this item.If all you want is to rotate or scale an item, you should call
setRotation()
orsetScale()
instead. If you want to set an arbitrary transformation on an item, you can callsetTransform()
.QGraphicsTransform
is for applying and controlling a chain of individual transformation operations on an item. It’s particularly useful in animations, where each transform operation needs to be interpolated independently, or differently.The transformations are combined with the item’s
rotation()
,scale()
andtransform()
to map the item’s coordinate system to the parent item.See also
transformations()
scale()
setTransformOriginPoint()
Transformations
- PySide2.QtWidgets.QGraphicsItem.setVisible(visible)¶
- Parameters:
visible – bool
If
visible
is true, the item is made visible. Otherwise, the item is made invisible. Invisible items are not painted, nor do they receive any events. In particular, mouse events pass right through invisible items, and are delivered to any item that may be behind. Invisible items are also unselectable, they cannot take input focus, and are not detected byQGraphicsScene
‘s item location functions.If an item becomes invisible while grabbing the mouse, (i.e., while it is receiving mouse events,) it will automatically lose the mouse grab, and the grab is not regained by making the item visible again; it must receive a new mouse press to regain the mouse grab.
Similarly, an invisible item cannot have focus, so if the item has focus when it becomes invisible, it will lose focus, and the focus is not regained by simply making the item visible again.
If you hide a parent item, all its children will also be hidden. If you show a parent item, all children will be shown, unless they have been explicitly hidden (i.e., if you call (false) on a child, it will not be reshown even if its parent is hidden, and then shown again).
Items are visible by default; it is unnecessary to call on a new item.
Note
An item with opacity set to 0 will still be considered visible, although it will be treated like an invisible item: mouse events will pass through it, it will not be included in the items returned by
items()
, and so on. However, the item will retain the focus.See also
- PySide2.QtWidgets.QGraphicsItem.setX(x)¶
- Parameters:
x – float
Set’s the
x
coordinate of the item’s position. Equivalent to callingsetPos
(x,y()
).
- PySide2.QtWidgets.QGraphicsItem.setY(y)¶
- Parameters:
y – float
Set’s the
y
coordinate of the item’s position. Equivalent to callingsetPos
(x()
, y).
- PySide2.QtWidgets.QGraphicsItem.setZValue(z)¶
- Parameters:
z – float
Sets the Z-value of the item to
z
. The Z value decides the stacking order of sibling (neighboring) items. A sibling item of high Z value will always be drawn on top of another sibling item with a lower Z value.If you restore the Z value, the item’s insertion order will decide its stacking order.
The Z-value does not affect the item’s size in any way.
The default Z-value is 0.
See also
zValue()
Sorting
stackBefore()
ItemStacksBehindParent
- PySide2.QtWidgets.QGraphicsItem.shape()¶
- Return type:
Returns the shape of this item as a
QPainterPath
in local coordinates. The shape is used for many things, including collision detection, hit tests, and for theitems()
functions.The default implementation calls
boundingRect()
to return a simple rectangular shape, but subclasses can reimplement this function to return a more accurate shape for non-rectangular items. For example, a round item may choose to return an elliptic shape for better collision detection. For example:def shape(self): path = QPainterPath() path.addEllipse(boundingRect()) return path
The outline of a shape can vary depending on the width and style of the pen used when drawing. If you want to include this outline in the item’s shape, you can create a shape from the stroke using
QPainterPathStroker
.This function is called by the default implementations of
contains()
andcollidesWithPath()
.See also
boundingRect()
contains()
prepareGeometryChange()
QPainterPathStroker
- PySide2.QtWidgets.QGraphicsItem.show()¶
Shows the item (items are visible by default).
This convenience function is equivalent to calling
setVisible(true)
.See also
- PySide2.QtWidgets.QGraphicsItem.stackBefore(sibling)¶
- Parameters:
sibling –
PySide2.QtWidgets.QGraphicsItem
Stacks this item before
sibling
, which must be a sibling item (i.e., the two items must share the same parent item, or must both be toplevel items). Thesibling
must have the same Z value as this item, otherwise calling this function will have no effect.By default, all sibling items are stacked by insertion order (i.e., the first item you add is drawn before the next item you add). If two items’ Z values are different, then the item with the highest Z value is drawn on top. When the Z values are the same, the insertion order will decide the stacking order.
See also
setZValue()
ItemStacksBehindParent
Sorting
- PySide2.QtWidgets.QGraphicsItem.toGraphicsObject()¶
- Return type:
Return the graphics item cast to a
QGraphicsObject
, if the class is actually a graphics object, 0 otherwise.
- PySide2.QtWidgets.QGraphicsItem.toolTip()¶
- Return type:
str
Returns the item’s tool tip, or an empty
QString
if no tool tip has been set.See also
- PySide2.QtWidgets.QGraphicsItem.topLevelItem()¶
- Return type:
Returns this item’s top-level item. The top-level item is the item’s topmost ancestor item whose parent is
None
. If an item has no parent, its own pointer is returned (i.e., a top-level item is its own top-level item).See also
- PySide2.QtWidgets.QGraphicsItem.topLevelWidget()¶
- Return type:
Returns a pointer to the item’s top level widget (i.e., the item’s ancestor whose parent is
None
, or whose parent is not a widget), orNone
if this item does not have a top level widget. If the item is its own top level widget, this function returns a pointer to the item itself.
- PySide2.QtWidgets.QGraphicsItem.transform()¶
- Return type:
Returns this item’s transformation matrix.
The transformation matrix is combined with the item’s
rotation()
,scale()
andtransformations()
into a combined transformations for the item.The default transformation matrix is an identity matrix.
See also
- PySide2.QtWidgets.QGraphicsItem.transformOriginPoint()¶
- Return type:
Returns the origin point for the transformation in item coordinates.
The default is
QPointF
(0,0).See also
setTransformOriginPoint()
Transformations
- PySide2.QtWidgets.QGraphicsItem.transformations()¶
- Return type:
Returns a list of graphics transforms that currently apply to this item.
QGraphicsTransform
is for applying and controlling a chain of individual transformation operations on an item. It’s particularly useful in animations, where each transform operation needs to be interpolated independently, or differently.The transformations are combined with the item’s
rotation()
,scale()
andtransform()
to map the item’s coordinate system to the parent item.See also
setTransformations()
scale()
rotation()
transformOriginPoint()
Transformations
- PySide2.QtWidgets.QGraphicsItem.type()¶
- Return type:
int
Returns the type of an item as an int. All standard graphicsitem classes are associated with a unique value; see
Type
. This type information is used byqgraphicsitem_cast()
to distinguish between types.The default implementation (in
QGraphicsItem
) returnsUserType
.To enable use of
qgraphicsitem_cast()
with a custom item, reimplement this function and declare a Type enum value equal to your custom item’s type. Custom items must return a value larger than or equal toUserType
(65536).For example:
class CustomItem(QGraphicsItem): ... self.Type = QGraphicsItem.UserType + 1 def type(self): # Enable the use of qgraphicsitem_cast with this item. return self.Type ...
See also
UserType
- PySide2.QtWidgets.QGraphicsItem.ungrabKeyboard()¶
Releases the keyboard grab.
See also
- PySide2.QtWidgets.QGraphicsItem.ungrabMouse()¶
Releases the mouse grab.
See also
- PySide2.QtWidgets.QGraphicsItem.unsetCursor()¶
Clears the cursor from this item.
See also
- PySide2.QtWidgets.QGraphicsItem.update([rect=QRectF()])¶
- Parameters:
rect –
PySide2.QtCore.QRectF
Schedules a redraw of the area covered by
rect
in this item. You can call this function whenever your item needs to be redrawn, such as if it changes appearance or size.This function does not cause an immediate paint; instead it schedules a paint request that is processed by
QGraphicsView
after control reaches the event loop. The item will only be redrawn if it is visible in any associated view.As a side effect of the item being repainted, other items that overlap the area
rect
may also be repainted.If the item is invisible (i.e.,
isVisible()
returnsfalse
), this function does nothing.See also
- PySide2.QtWidgets.QGraphicsItem.update(x, y, width, height)
- Parameters:
x – float
y – float
width – float
height – float
This is an overloaded function.
This convenience function is equivalent to calling update(
QRectF
(x
,y
,width
,height
)).
- PySide2.QtWidgets.QGraphicsItem.updateMicroFocus()¶
Updates the item’s micro focus.
See also
QInputMethod
- PySide2.QtWidgets.QGraphicsItem.wheelEvent(event)¶
- Parameters:
This event handler, for event
event
, can be reimplemented to receive wheel events for this item. If you reimplement this function,event
will be accepted by default.If you ignore the event, (i.e., by calling
ignore()
,) it will propagate to any item beneath this item. If no items accept the event, it will be ignored by the scene, and propagate to the view (e.g., the view’s vertical scroll bar).The default implementation ignores the event.
See also
- PySide2.QtWidgets.QGraphicsItem.window()¶
- Return type:
Returns the item’s window, or
None
if this item does not have a window. If the item is a window, it will return itself. Otherwise it will return the closest ancestor that is a window.See also
isWindow()
- PySide2.QtWidgets.QGraphicsItem.x()¶
- Return type:
float
This convenience function is equivalent to calling
pos()
..
- PySide2.QtWidgets.QGraphicsItem.y()¶
- Return type:
float
This convenience function is equivalent to calling
pos()
..
- PySide2.QtWidgets.QGraphicsItem.zValue()¶
- Return type:
float
Returns the Z-value of the item. The Z-value affects the stacking order of sibling (neighboring) items.
The default Z-value is 0.
See also
setZValue()
Sorting
stackBefore()
ItemStacksBehindParent
© 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.