QGraphicsRectItem 类提供的矩形项可以被添加到 QGraphicsScene . 更多...
| 头: | #include <QGraphicsRectItem> | 
| CMake: | find_package(Qt6 COMPONENTS Widgets REQUIRED) target_link_libraries(mytarget PRIVATE Qt6::Widgets) | 
| qmake: | QT += widgets | 
| 继承: | QAbstractGraphicsShapeItem | 
| 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 ,和 图形视图框架 .
值的返回通过虚拟 type () 函数。
| 常量 | 值 | 描述 | 
|---|---|---|
| 
QGraphicsRectItem::Type
								 | 
3
								 | 图形矩形项 | 
将项的矩形设为矩形,定义通过 ( x , y ) 和给定 width and height .
						此方便函数相当于调用
						
setRect(QRectF(x, y, width, height))
						
					
另请参阅 rect ().
构造 QGraphicsRectItem 采用默认矩形定义通过 ( x , y ) 和给定 width and height .
parent 会被传递给 QAbstractGraphicsShapeItem 的构造函数。
另请参阅 QGraphicsScene::addItem ().
构造 QGraphicsRectItem,使用 rect 作为默认矩形。 parent 会被传递给 QAbstractGraphicsShapeItem 的构造函数。
另请参阅 QGraphicsScene::addItem ().
构造 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).
返回项的矩形。
另请参阅 setRect ().
将项的矩形设为给定 rectangle .
另请参阅 rect ().
[override virtual]
						
						
							
								QPainterPath
							
						
						QGraphicsRectItem::
						
							shape
						
						() const
						
					重实现: QGraphicsItem::shape () const.
[override virtual]
						
						
							int
						
						QGraphicsRectItem::
						
							type
						
						() const
						
					重实现: QGraphicsItem::type () const.