QGraphicsRectItem 类

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

头: #include <QGraphicsRectItem>
qmake: QT += widgets
Since: 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 .

要设置项的矩形,传递 QRectF to QGraphicsRectItem 's constructor, or call the setRect () 函数。 rect () 函数返回当前矩形。

QGraphicsRectItem uses the rectangle and the pen width to provide a reasonable implementation of boundingRect (), shape (),和 contains ()。 paint () function draws the rectangle using the item's associated pen and brush, which you can set by calling the setPen () 和 setBrush () 函数。

注意: 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 ,和 图形视图框架 .

成员函数文档编制

QGraphicsRectItem:: QGraphicsRectItem ( QGraphicsItem * parent = Q_NULLPTR)

构造 QGraphicsRectItem . parent 会被传递给 QAbstractGraphicsShapeItem 的构造函数。

另请参阅 QGraphicsScene::addItem ().

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

构造 QGraphicsRectItem ,使用 rect 作为默认矩形。 parent 会被传递给 QAbstractGraphicsShapeItem 的构造函数。

另请参阅 QGraphicsScene::addItem ().

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

构造 QGraphicsRectItem with a default rectangle defined by ( x , y ) 和给定 width and height .

parent 会被传递给 QAbstractGraphicsShapeItem 的构造函数。

另请参阅 QGraphicsScene::addItem ().

QGraphicsRectItem:: ~QGraphicsRectItem ()

销毁 QGraphicsRectItem .

[虚拟] QRectF QGraphicsRectItem:: boundingRect () const

重实现自 QGraphicsItem::boundingRect ().

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

重实现自 QGraphicsItem::contains ().

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

重实现自 QGraphicsItem::isObscuredBy ().

[虚拟] QPainterPath QGraphicsRectItem:: opaqueArea () const

重实现自 QGraphicsItem::opaqueArea ().

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

重实现自 QGraphicsItem::paint ().

QRectF QGraphicsRectItem:: rect () const

返回项的矩形。

另请参阅 setRect ().

void QGraphicsRectItem:: setRect (const QRectF & rectangle )

将项的矩形设为给定 rectangle .

另请参阅 rect ().

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

将项的矩形设为矩形,定义通过 ( x , y ) 和给定 width and height .

此方便函数相当于调用 setRect(QRectF(x, y, width, height))

另请参阅 rect ().

[虚拟] QPainterPath QGraphicsRectItem:: shape () const

重实现自 QGraphicsItem::shape ().

[虚拟] int QGraphicsRectItem:: type () const

重实现自 QGraphicsItem::type ().