En esta página

QGraphicsRectItem Class

La clase QGraphicsRectItem proporciona un elemento rectángulo que se puede añadir a un QGraphicsScene. Más...

Cabecera: #include <QGraphicsRectItem>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
Hereda: 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 ancho del lápiz para proporcionar una implementación razonable de boundingRect(), shape(), y contains(). La función paint() dibuja el rectángulo usando el lápiz y el pincel asociados al ítem, que puedes establecer llamando a las funciones setPen() y setBrush().

Nota: La representación de rectángulos no válidos, como los de anchura o altura negativas, es indefinida. Si no puede estar seguro de que está utilizando rectángulos válidos (por ejemplo, si está creando rectángulos utilizando datos de una fuente poco fiable) entonces debería utilizar QRectF::normalized() para crear rectángulos normalizados, y utilizarlos en su lugar.

Ver también QGraphicsPathItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, y Graphics View Framework.

Documentación de tipos de miembros

[anonymous] enum

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

ConstanteValorDescripción
QGraphicsRectItem::Type3Un elemento gráfico rect

Documentación de la función miembro

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

Construye un QGraphicsRectItem. parent es pasado al constructor de QAbstractGraphicsShapeItem.

Ver también QGraphicsScene::addItem().

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

Construye un QGraphicsRectItem, usando rect como rectángulo por defecto. parent se pasa al constructor de QAbstractGraphicsShapeItem.

Ver también QGraphicsScene::addItem().

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

Construye un QGraphicsRectItem con un rectángulo por defecto definido por (x, y) y los dados width y height.

parent se pasa al constructor de QAbstractGraphicsShapeItem.

Ver 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 la dirección 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 width y height.

Esta función es equivalente 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.