QGraphicsRectItem Class
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 |
详细说明
要设置项目的矩形,请向 QGraphicsRectItem 的构造函数传递QRectF 或调用setRect() 函数。rect() 函数将返回当前矩形。
QGraphicsRectItem 使用矩形和笔宽来合理实现boundingRect()、shape() 和contains()。paint() 函数使用项的相关笔和笔刷绘制矩形,您可以通过调用setPen() 和setBrush() 函数设置笔和笔刷。
注意: 无效矩形(如宽度或高度为负数的矩形)的呈现是未定义的。如果不能确定使用的是有效的矩形(例如,使用不可靠的数据源创建的矩形),则应使用QRectF::normalized() 创建规范化矩形,然后使用这些矩形。
另请参阅 QGraphicsPathItem,QGraphicsEllipseItem,QGraphicsPolygonItem,QGraphicsTextItem,QGraphicsLineItem,QGraphicsPixmapItem 和图形视图框架。
成员函数文档
void QGraphicsRectItem::setRect(qreal x, qreal y, qreal width, qreal height)
将项目的矩形设置为 (x,y) 以及给定的width 和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 和height 定义。
parent 传递给 的构造函数。QAbstractGraphicsShapeItem
另请参阅 QGraphicsScene::addItem().
[virtual noexcept]
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.
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.