本页内容

QPaintEvent Class

QPaintEvent 类包含绘制事件的事件参数。更多内容...

头文件: #include <QPaintEvent>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承自: QEvent

公共函数

QPaintEvent(const QRect &paintRect)
QPaintEvent(const QRegion &paintRegion)
const QRect &rect() const
const QRegion &region() const

受保护函数

QPaintEvent(QPaintEvent &&)
QPaintEvent &operator=(QPaintEvent &&)
QPaintEvent &operator=(const QPaintEvent &other)

详细说明

绘制事件会发送给需要更新的控件,例如当覆盖控件被移动,导致控件的一部分暴露出来时。

该事件包含一个需要更新的region(),以及一个代表该区域边界矩形的rect()。之所以同时提供这两个参数,是因为许多控件无法充分利用region(),而且rect() 的速度可能远快于region(boundingRect())。

自动裁剪

在处理绘制事件期间,绘制操作会根据region()进行裁剪。此裁剪由Qt的绘制系统执行,与用于在绘制设备上绘制的QPainter 可能应用的任何裁剪操作均无关。

因此,在新生成的QPainter 上,QPainter::clipRegion() 返回的值不会反映绘制系统所使用的裁剪区域。

另请参阅 QPainter 、QWidget::update()、QWidget::repaint() 和QWidget::paintEvent()。

成员函数文档

[explicit] QPaintEvent::QPaintEvent(const QRect &paintRect)

根据需要更新的矩形构建一个绘制事件对象。该区域由paintRect 指定。

[explicit] QPaintEvent::QPaintEvent(const QRegion &paintRegion)

根据需要更新的区域创建一个绘制事件对象。该区域由paintRegion 指定。

[protected delete] QPaintEvent::QPaintEvent(QPaintEvent &&)

通过移动构造创建一个QPaintEvent 的实例。该函数已被删除。

const QRect &QPaintEvent::rect() const

返回需要更新的矩形。

另请参阅 region() 和QPainter::setClipRect()。

const QRegion &QPaintEvent::region() const

返回需要更新的区域。

另请参阅 rect() 和QPainter::setClipRegion()。

[protected delete] QPaintEvent &QPaintEvent::operator=(QPaintEvent &&)

将other 按移动赋值方式赋值给此QPaintEvent 实例。该函数已被删除。

[noexcept protected default] QPaintEvent &QPaintEvent::operator=(const QPaintEvent &other)

将other 复制并赋值给此QPaintEvent 实例。

© 2026 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.