En esta página

QGraphicsRectItem Class

La clase `QGraphicsRectItem` proporciona un elemento rectangular que se puede añadir a un ` QGraphicsScene`. Más información...

Encabezado: #include <QGraphicsRectItem>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
Heredan: QAbstractGraphicsShapeItem

Tipos públicos

enum { Type }

Funciones públicas

QGraphicsRectItem(QGraphicsItem *parent = nullptr)
QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent = nullptr)
QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = nullptr)
virtual ~QGraphicsRectItem()
QRectF rect() const
void setRect(const QRectF &rectangle)
void setRect(qreal x, qreal y, qreal width, qreal height)

Funciones públicas reimplementadas

virtual QRectF boundingRect() const override
virtual bool contains(const QPointF &point) const override
virtual bool isObscuredBy(const QGraphicsItem *item) const override
virtual QPainterPath opaqueArea() const override
virtual void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr) override
virtual QPainterPath shape() const override
virtual int type() const override

Descripción detallada

Para establecer el rectángulo del elemento, pasa un ` QRectF ` al constructor de `QGraphicsRectItem` o llama a la función ` setRect()`. La función ` rect()` devuelve el rectángulo actual.

Rectángulo dibujado cerca del origen

QGraphicsRectItem utiliza el rectángulo y el grosor del trazo para proporcionar una implementación razonable de boundingRect(), shape() y contains(). La función paint() dibuja el rectángulo utilizando el trazo y el pincel asociados al elemento, que se pueden configurar llamando a las funciones setPen() y setBrush().

Nota: El resultado de la representación de rectángulos no válidos, como aquellos con anchuras o alturas negativas, es indefinido. Si no estás seguro de que estés utilizando rectángulos válidos (por ejemplo, si estás creando rectángulos a partir de datos de una fuente poco fiable), debes utilizar QRectF::normalized() para crear rectángulos normalizados y utilizar estos en su lugar.

Véase también QGraphicsPathItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem y el marco de trabajo Graphics View.

Documentación sobre los tipos de miembros

[anonymous] enum

El valor devuelto por la función virtual ` type()`.

ConstanteValorDescripción
QGraphicsRectItem::Type3Un elemento rect de gráficos

Documentación de la función miembro

[explicit] QGraphicsRectItem::QGraphicsRectItem(QGraphicsItem *parent = nullptr)

Crea un objeto `QGraphicsRectItem`. Se pasa ` parent ` al constructor de ` QAbstractGraphicsShapeItem`.

Véase también QGraphicsScene::addItem().

[explicit] QGraphicsRectItem::QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent = nullptr)

Crea un objeto `QGraphicsRectItem` utilizando ` rect ` como rectángulo por defecto. Se pasa ` parent ` al constructor de ` QAbstractGraphicsShapeItem`.

Véase también QGraphicsScene::addItem().

[explicit] QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = nullptr)

Crea un objeto `QGraphicsRectItem` con un rectángulo predeterminado definido por (x, y) y los valores proporcionados para ` width ` y ` height`.

parent Se pasa al constructor de QAbstractGraphicsShapeItem.

Véase también QGraphicsScene::addItem().

[virtual noexcept] QGraphicsRectItem::~QGraphicsRectItem()

Destruye el « QGraphicsRectItem ».

[override virtual] QRectF QGraphicsRectItem::boundingRect() const

Reimplementa: ` QGraphicsItem::boundingRect()` const.

[override virtual] bool QGraphicsRectItem::contains(const QPointF &point) const

Reimplementa: ` QGraphicsItem::contains(const QPointF &point) const`.

[override virtual] bool QGraphicsRectItem::isObscuredBy(const QGraphicsItem *item) const

Reimplementa: QAbstractGraphicsShapeItem::isObscuredBy(const QGraphicsItem *item) const.

[override virtual] QPainterPath QGraphicsRectItem::opaqueArea() const

Reimplementa: ` QAbstractGraphicsShapeItem::opaqueArea()` const.

[override virtual] void QGraphicsRectItem::paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = nullptr)

Reimplementa: ` QGraphicsItem::paint` (`QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget)`.

QRectF QGraphicsRectItem::rect() const

Devuelve el rectángulo del elemento.

Véase también setRect().

void QGraphicsRectItem::setRect(const QRectF &rectangle)

Establece el rectángulo del elemento en el valor indicado: rectangle.

Véase también rect().

void QGraphicsRectItem::setRect(qreal x, qreal y, qreal width, qreal height)

Establece el rectángulo del elemento en el rectángulo definido por (x, y) y los valores proporcionados width y height.

Esta función de conveniencia equivale a llamar a setRect(QRectF(x, y, width, height))

Véase también rect().

[override virtual] QPainterPath QGraphicsRectItem::shape() const

Reimplementa: QGraphicsItem::shape() const.

[override virtual] int QGraphicsRectItem::type() const

Reimplementa: ` QGraphicsItem::type()` const.

© 2026 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.