QGraphicsRectItem 类

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

头: #include <QGraphicsRectItem>
CMake: find_package(Qt6 REQUIRED COMPONENTS Widgets)
target_link_libraries(mytarget PRIVATE Qt6::Widgets)
qmake: QT += widgets
继承: 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

详细描述

要设置项的矩形,传递 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 ().

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

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

另请参阅 QGraphicsScene::addItem ().

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

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

另请参阅 QGraphicsScene::addItem ().

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

构造 QGraphicsRectItem 采用默认矩形定义通过 ( x , y ) 和给定 width and height .

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

另请参阅 QGraphicsScene::addItem ().

[virtual noexcept] 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 .