QGraphicsRectItem 類

QGraphicsRectItem 類提供的矩形項可以被添加到 QGraphicsScene . 更多...

頭: #include <QGraphicsRectItem>
qmake: QT += widgets
Since: Qt 4.2
繼承: QAbstractGraphicsShapeItem

該類在 Qt 4.2 引入。

公共類型

enum anonymous { Type }

公共函數

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

重實現公共函數

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

詳細描述

要設置項的矩形,傳遞 QRectF 給 QGraphicsRectItem 的構造函數,或調用 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 ,和 圖形視圖框架 .

成員類型文檔編製

enum QGraphicsRectItem:: anonymous

值的返迴是通過虛擬 type () 函數。

常量 描述
QGraphicsRectItem::Type 3 圖形矩形項

成員函數文檔編製

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

將項的矩形設為矩形,定義通過 ( x , y ) 和給定 width and height .

此方便函數相當於調用 setRect(QRectF(x, y, width, height))

另請參閱 rect ().

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

構造 QGraphicsRectItem 采用默認矩形定義通過 ( x , y ) 和給定 width and height .

parent 被傳遞給 QAbstractGraphicsShapeItem 的構造函數。

另請參閱 QGraphicsScene::addItem ().

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

構造 QGraphicsRectItem,使用 rect 作為默認矩形。 parent 被傳遞給 QAbstractGraphicsShapeItem 的構造函數。

另請參閱 QGraphicsScene::addItem ().

QGraphicsRectItem:: QGraphicsRectItem ( QGraphicsItem * parent = nullptr)

構造 QGraphicsRectItem。 parent 被傳遞給 QAbstractGraphicsShapeItem 的構造函數。

另請參閱 QGraphicsScene::addItem ().

[虛擬] QGraphicsRectItem:: ~QGraphicsRectItem ()

銷毀 QGraphicsRectItem .

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

重實現: QGraphicsItem::boundingRect () const.

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

重實現: QGraphicsItem::contains (const QPointF &point) const.

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

重實現: QAbstractGraphicsShapeItem::isObscuredBy (const QGraphicsItem *item) const.

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

重實現: QAbstractGraphicsShapeItem::opaqueArea () const.

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

重實現: QGraphicsItem::paint (QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget).

QRectF QGraphicsRectItem:: rect () const

返迴項的矩形。

另請參閱 setRect ().

void QGraphicsRectItem:: setRect (const QRectF & rectangle )

將項的矩形設為給定 rectangle .

另請參閱 rect ().

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

重實現: QGraphicsItem::shape () const.

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

重實現: QGraphicsItem::type () const.