class QGraphicsRectItem

The QGraphicsRectItem class provides a rectangle item that you can add to a QGraphicsScene . More

Inheritance diagram of PySide6.QtWidgets.QGraphicsRectItem

Synopsis

Methods

Note

This documentation may contain snippets that were automatically translated from C++ to Python. We always welcome contributions to the snippet translation. If you see an issue with the translation, you can also let us know by creating a ticket on https:/bugreports.qt.io/projects/PYSIDE

Detailed Description

To set the item’s rectangle, pass a QRectF to QGraphicsRectItem ‘s constructor, or call the setRect() function. The rect() function returns the current rectangle.

../../_images/graphicsview-rectitem.png

QGraphicsRectItem uses the rectangle and the pen width to provide a reasonable implementation of boundingRect() , shape() , and contains() . The paint() function draws the rectangle using the item’s associated pen and brush, which you can set by calling the setPen() and setBrush() functions.

Note

The rendering of invalid rectangles, such as those with negative widths or heights, is undefined. If you cannot be sure that you are using valid rectangles (for example, if you are creating rectangles using data from an unreliable source) then you should use QRectF::normalized() to create normalized rectangles, and use those instead.

__init__([parent=None])
Parameters:

parentQGraphicsItem

Constructs a QGraphicsRectItem . parent is passed to QAbstractGraphicsShapeItem ‘s constructor.

See also

addItem()

__init__(rect[, parent=None])
Parameters:

Constructs a QGraphicsRectItem , using rect as the default rectangle. parent is passed to QAbstractGraphicsShapeItem ‘s constructor.

See also

addItem()

__init__(x, y, w, h[, parent=None])
Parameters:
  • x – float

  • y – float

  • w – float

  • h – float

  • parentQGraphicsItem

Constructs a QGraphicsRectItem with a default rectangle defined by (x, y) and the given width and height.

parent is passed to QAbstractGraphicsShapeItem ‘s constructor.

See also

addItem()

rect()
Return type:

QRectF

Returns the item’s rectangle.

See also

setRect()

setRect(rect)
Parameters:

rectQRectF

Sets the item’s rectangle to be the given rectangle.

See also

rect()

setRect(x, y, w, h)
Parameters:
  • x – float

  • y – float

  • w – float

  • h – float