本页内容

QBackingStore Class

QBackingStore 类为QWindow 提供了一个绘图区域。更多内容...

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

公共函数

QBackingStore(QWindow *window)
~QBackingStore()
void beginPaint(const QRegion &region)
void endPaint()
void flush(const QRegion &region, QWindow *window = nullptr, const QPoint &offset = QPoint())
QPlatformBackingStore *handle() const
bool hasStaticContents() const
QPaintDevice *paintDevice()
void resize(const QSize &size)
bool scroll(const QRegion &area, int dx, int dy)
void setStaticContents(const QRegion &region)
QSize size() const
QRegion staticContents() const
QWindow *window() const

详细说明

QBackingStore 支持使用QPainter 在类型为 RasterSurface 的QWindow 上进行绘制。渲染到QWindow 的另一种方式是通过 OpenGL 并使用QOpenGLContext 。

一个 QBackingStore 包含窗口内容的缓冲表示,因此支持通过使用QPainter 仅更新窗口内容的子区域来实现部分更新。

对于希望在不使用 OpenGL 加速且避免使用QWidget 或QGraphicsView UI 堆栈所带来的额外开销的情况下使用QPainter 的应用程序,可以使用 QBackingStore。有关如何使用 QBackingStore 的示例,请参阅“光栅窗口示例”。

成员函数文档

[explicit] QBackingStore::QBackingStore(QWindow *window)

为给定的顶级window 构建一个空表面。

[noexcept] QBackingStore::~QBackingStore()

破坏该表面。

void QBackingStore::beginPaint(const QRegion &region)

开始在给定的region 中对后备存储表面进行绘制。

在使用paintDevice() 进行绘制之前,应先调用此函数。

另请参阅 endPaint() 和paintDevice()。

void QBackingStore::endPaint()

结束绘制。

应在paintDevice()绘制完成后调用此函数。

另请参阅 beginPaint() 和paintDevice()。

void QBackingStore::flush(const QRegion &region, QWindow *window = nullptr, const QPoint &offset = QPoint())

将指定的region 从指定的window 刷新到屏幕上。

该window 必须是该backingstore所表示的顶级窗口,或是该窗口的一个非临时子窗口。若传入nullptr ,则会回退到使用backingstore的顶级窗口。

如果 `window ` 是子窗口,则 `region ` 应采用子窗口坐标系,而 `offset ` 应表示该子窗口相对于该 backingstore 顶级窗口的偏移量。

您应在通过 `endPaint()` 结束绘制操作后调用此函数。

QPlatformBackingStore *QBackingStore::handle() const

返回指向 QPlatformBackingStore 实现的指针

bool QBackingStore::hasStaticContents() const

返回一个布尔值,用于指示该窗口是否包含静态内容。

QPaintDevice *QBackingStore::paintDevice()

返回该表面的绘制设备。

警告:该 设备仅在调用beginPaint()和endPaint()之间有效。请勿缓存返回值。

void QBackingStore::resize(const QSize &size)

将窗口画布的大小设置为size 。

另请参阅 size()。

bool QBackingStore::scroll(const QRegion &area, int dx, int dy)

将指定的area 向右滚动dx 像素,并向下滚动dy 像素;dx 和dy 均可为负数。

如果该区域滚动成功,则返回true ;否则返回 false。

void QBackingStore::setStaticContents(const QRegion &region)

将region 设置为该窗口的静态内容。

另请参阅 staticContents()。

QSize QBackingStore::size() const

返回窗口表面的当前大小。

QRegion QBackingStore::staticContents() const

返回一个表示窗口中静态内容区域的QRegion 对象。

另请参阅 setStaticContents()。

QWindow *QBackingStore::window() const

返回指向与该绘图区域关联的顶级窗口的指针。

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