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

公共類型

enum anonymous { Type }

公共函數

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 )

重實現公共函數

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

額外繼承成員

詳細描述

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 ,和 圖形視圖框架 .

成員類型文檔編製

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 ( QGraphicsItem * parent = nullptr)

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

另請參閱 QGraphicsScene::addItem ().

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

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

另請參閱 QGraphicsScene::addItem ().

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

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

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

另請參閱 QGraphicsScene::addItem ().

[虛擬] QGraphicsRectItem:: ~QGraphicsRectItem ()

銷毀 QGraphicsRectItem .

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

重實現自 QGraphicsItem::boundingRect ().

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

重實現自 QGraphicsItem::contains ().

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

重實現自 QAbstractGraphicsShapeItem::isObscuredBy ().

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

重實現自 QAbstractGraphicsShapeItem::opaqueArea ().

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

重實現自 QGraphicsItem::paint ().

QRectF QGraphicsRectItem:: rect () const

返迴項的矩形。

另請參閱 setRect ().

void QGraphicsRectItem:: setRect (const QRectF & rectangle )

將項的矩形設為給定 rectangle .

另請參閱 rect ().

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

重實現自 QGraphicsItem::shape ().

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

重實現自 QGraphicsItem::type ().