QGraphicsRectItem Class

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

头文件: #include <QGraphicsRectItem>
qmake: QT += widgets
开始支持版本: Qt 4.2
基类: QAbstractGraphicsShapeItem

公有函数

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

重新实现的公有函数

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

其他继承的成员

详细描述

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

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.

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.

参见 QGraphicsPathItem, QGraphicsEllipseItem, QGraphicsPolygonItem, QGraphicsTextItem, QGraphicsLineItem, QGraphicsPixmapItem, and Graphics View Framework.

成员函数

QGraphicsRectItem::QGraphicsRectItem(QGraphicsItem *parent = Q_NULLPTR)

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

参见 QGraphicsScene::addItem().

QGraphicsRectItem::QGraphicsRectItem(const QRectF &rect, QGraphicsItem *parent = Q_NULLPTR)

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

参见 QGraphicsScene::addItem().

QGraphicsRectItem::QGraphicsRectItem(qreal x, qreal y, qreal width, qreal height, QGraphicsItem *parent = Q_NULLPTR)

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

parent is passed to QAbstractGraphicsShapeItem's constructor.

参见 QGraphicsScene::addItem().

QGraphicsRectItem::~QGraphicsRectItem()

Destroys the QGraphicsRectItem.

[virtual] QRectF QGraphicsRectItem::boundingRect() const

重新实现 QGraphicsItem::boundingRect().

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

重新实现 QGraphicsItem::contains().

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

重新实现 QGraphicsItem::isObscuredBy().

[virtual] QPainterPath QGraphicsRectItem::opaqueArea() const

重新实现 QGraphicsItem::opaqueArea().

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

重新实现 QGraphicsItem::paint().

QRectF QGraphicsRectItem::rect() const

Returns the item's rectangle.

参见 setRect().

void QGraphicsRectItem::setRect(const QRectF &rectangle)

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

参见 rect().

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

Sets the item's rectangle to the rectangle defined by (x, y) and the given width and height.

This convenience function is equivalent to calling setRect(QRectF(x, y, width, height))

参见 rect().

[virtual] QPainterPath QGraphicsRectItem::shape() const

重新实现 QGraphicsItem::shape().

[virtual] int QGraphicsRectItem::type() const

重新实现 QGraphicsItem::type().