本页内容

Qt3DRender::QPaintedTextureImage Class

class Qt3DRender::QPaintedTextureImage

一个可通过QPainter 进行写入的QAbstractTextureImage 。更多内容...

标题: #include <qpaintedtextureimage.h>
CMake: find_package(Qt6 REQUIRED COMPONENTS 3drender)
target_link_libraries(mytarget PRIVATE Qt6::3drender)
qmake: QT += 3drender
继承自: Qt3DRender::QAbstractTextureImage
状态: 已弃用

该类已弃用。我们强烈建议不要在新的代码中使用它。

属性

公共函数

int height() const
QSize size() const
void update(const QRect &rect = QRect())
int width() const

公共槽位

void setHeight(int h)
void setSize(QSize size)
void setWidth(int w)

信号

void heightChanged(int w)
void sizeChanged(QSize size)
void widthChanged(int w)

受保护函数

virtual void paint(QPainter *painter) = 0

详细说明

QPaintedTextureImage 提供了一种通过QPainter 指定纹理图像(即 OpenGL 纹理)的方法。纹理图像的宽度和高度可通过 width、height 或 size 属性进行指定。

必须对 QPaintedTextureImage 进行子类化,并实现虚拟函数paint()。每当在 QPaintedTextureImage 上调用update() 时,都会调用paint() 函数,并将生成的图像上传。

QPaintedTextureImage必须附加到某个QAbstractTexture 上。

属性文档

height : int

该属性存储纹理图像的高度。高度必须大于或等于 1。

访问函数:

int height() const
void setHeight(int h)

通知信号:

void heightChanged(int w)

size : QSize

该属性存储纹理图像的大小。

访问函数:

QSize size() const
void setSize(QSize size)

通知信号:

void sizeChanged(QSize size)

另请参阅 height 和width 。

width : int

该属性存储纹理图像的宽度。宽度必须大于或等于 1。

访问函数:

int width() const
void setWidth(int w)

通知信号:

void widthChanged(int w)

成员函数文档

[pure virtual protected] void QPaintedTextureImage::paint(QPainter *painter)

使用指定的QPainter 对象painter 绘制纹理图像。

QPainter 将图像的左上角视为原点,而 OpenGL 则将纹理的左下角视为原点。解决这一差异的简便方法是在进行任何其他绘制操作之前,先在绘制器上设置一个自定义视口:

painter->setViewport(0, height(), width(), -height());
...

[slot] void QPaintedTextureImage::setHeight(int h)

设置纹理图像的高度(h )。如果尺寸发生变化,则触发更新。

注意: 这是属性height 的设置 函数。

另请参阅 height()。

[slot] void QPaintedTextureImage::setSize(QSize size)

设置纹理图像的宽度和高度。如果size 发生变化,则触发更新。

注意: 这是属性 `size`的设置 函数。

另请参阅 size()。

[slot] void QPaintedTextureImage::setWidth(int w)

设置纹理图像的宽度(w )。如果尺寸发生变化,则触发更新。

注意: 这是属性width 的设置 函数。

另请参阅 width()。

void QPaintedTextureImage::update(const QRect &rect = QRect())

立即触发绘制纹理的paint()函数,该函数进而将新图像上传至GPU。如果您对绘制纹理进行了多次修改,请考虑在所有修改完成后再调用update,以尽量减少所需的重绘次数。

参数rect 目前未被使用。

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