このページでは

QCanvasOffscreenCanvas Class

QCanvasOffscreenCanvas は、QCanvasPainter がターゲットとすることができるオフスクリーン・キャンバスを表します。詳細...

ヘッダー: #include <QCanvasOffscreenCanvas>
CMake: find_package(Qt6 REQUIRED COMPONENTS CanvasPainter)
target_link_libraries(mytarget PRIVATE Qt6::CanvasPainter)
以下より: Qt 6.11

パブリック型

enum class Flag { PreserveContents, MipMaps }
flags Flags

パブリック関数

QCanvasOffscreenCanvas(const QCanvasOffscreenCanvas &canvas)
QCanvasOffscreenCanvas(QCanvasOffscreenCanvas &&other)
~QCanvasOffscreenCanvas()
QColor fillColor() const
QCanvasOffscreenCanvas::Flags flags() const
int height() const
bool isNull() const
void setFillColor(QColor color)
QSize size() const
QRhiTexture *texture() const
int width() const
QCanvasOffscreenCanvas &operator=(const QCanvasOffscreenCanvas &canvas)
bool operator!=(const QCanvasOffscreenCanvas &lhs, const QCanvasOffscreenCanvas &rhs)
bool operator==(const QCanvasOffscreenCanvas &lhs, const QCanvasOffscreenCanvas &rhs)

詳細な説明

オフスクリーン・キャンバスは、本質的にはカラーバッファ(QRhiTexture )であり、場合によってはその他の関連するグラフィック・リソースも含まれます。コンテンツがキャンバスのカラーバッファにレンダリングされた後、キャンバスをペインタにregistered することで、QCanvasImage を取得できます。この は、drawImage()呼び出しや、image pattern として使用できます。

オフスクリーン・キャンバスを作成するには、QCanvasPainter::createCanvas() を呼び出します。描画コマンドでオフスクリーン・キャンバスを指定するには、低レベル API を使用する場合は適切なQCanvasRhiPaintDriver::beginPaint() のオーバーロードを呼び出し、利便性の高いウィジェットやQt Quick アイテム・クラスを使用する場合はQCanvasPainterWidget::beginCanvasPainting() またはQCanvasPainterItemRenderer::beginCanvasPainting() を呼び出します。

QCanvasImage やQCanvasBrush と同様に、QCanvasOffscreenCanvasは明示的に共有されます。詳細については、「暗黙的なデータ共有」および「QSharedDataPointer 」を参照してください。

注: QCanvasImageと同様に 、QCanvasOffscreenCanvasは単にハンドルを含むオブジェクトと見なすことができます。切り離しが発生した場合でも、実際のリソース(例えば、基になるテクスチャやその中の画像データなど)が実際にコピーされたり複製されたりすることは決してありません。 実際のグラフィックリソース(例:QRhiTexture )の真の所有者は、createCanvas() を通じて QCanvasOffscreenCanvas を割り当てたQCanvasPainter です。

キャンバスは常に、それを作成したQCanvasPainter に属します。キャンバスを手動で破棄するには、destroyCanvas()を呼び出します。ただし、ほとんどの場合、ペインターが自身の破棄時に自動的にすべてのキャンバスを破棄するため、これを行う必要はありません。

メンバ型のドキュメント

enum class QCanvasOffscreenCanvas::Flag
flags QCanvasOffscreenCanvas::Flags

キャンバスのフラグを指定します。

定数値説明
QCanvasOffscreenCanvas::Flag::PreserveContents0x01キャンバスへの描画時に、その内容が保持されることを示します。GPUアーキテクチャによっては、パフォーマンスに悪影響を及ぼす可能性があります。詳細については、QRhiTextureRenderTarget::PreserveColorContents を参照してください。サンプル数が 1 より大きい場合、このフラグの設定はサポートされていません。
QCanvasOffscreenCanvas::Flag::MipMaps0x02キャンバスのバッキングテクスチャでミップマッピングを有効にすることを示します。サンプル数が 1 より大きい場合、このフラグの設定はサポートされません。GenerateMipmaps フラグを設定してaddImage() を呼び出すと、ミップマップシーケンスが生成されることに注意してください。 これは、ミップマップチェーンが再生成されるように、キャンバスの内容が変更されるたびに addImage() を呼び出す必要があることを意味します。頻繁なミップマップの生成は、パフォーマンスに悪影響を及ぼす可能性があります。

Flags 型はQFlags<Flag> の typedef です。Flag 値の論理和(OR)を格納します。

メンバ関数のドキュメント

QCanvasOffscreenCanvas::QCanvasOffscreenCanvas(const QCanvasOffscreenCanvas &canvas)

コピーコンストラクタ。

[constexpr noexcept default] QCanvasOffscreenCanvas::QCanvasOffscreenCanvas(QCanvasOffscreenCanvas &&other)

QCanvasOffscreenCanvas のインスタンスをMoveコンストラクタで生成します。

[noexcept] QCanvasOffscreenCanvas::~QCanvasOffscreenCanvas()

デストラクタ。

QColor QCanvasOffscreenCanvas::fillColor() const

現在の塗りつぶし色を返します。

setFillColor()も参照してください 。

QCanvasOffscreenCanvas::Flags QCanvasOffscreenCanvas::flags() const

キャンバスが作成された際に指定されたフラグを返します。

これらのフラグは不変であり、キャンバスが一度作成されると変更することはできません。

int QCanvasOffscreenCanvas::height() const

このキャンバスの高さをピクセル単位で返します。

width() およびsize()も参照してください 。

bool QCanvasOffscreenCanvas::isNull() const

このキャンバスに有効なデータがある場合、true を返します。

通常、これは常に true になります。

texture()も参照してください 。

void QCanvasOffscreenCanvas::setFillColor(QColor color)

塗りつぶし(背景)色を `color` に設定します。

デフォルトでは、これはcreateCanvas()に渡された値に設定されます。

fillColor()も参照してください 。

QSize QCanvasOffscreenCanvas::size() const

このキャンバスのサイズ(幅と高さ)をピクセル単位で返します。

width() およびheight()も参照してください 。

QRhiTexture *QCanvasOffscreenCanvas::texture() const

このオフスクリーン・キャンバスの基となるテクスチャを返します。

isNull()も参照してください 。

int QCanvasOffscreenCanvas::width() const

このキャンバスの幅をピクセル単位で返します。

height() およびsize()も参照してください 。

QCanvasOffscreenCanvas &QCanvasOffscreenCanvas::operator=(const QCanvasOffscreenCanvas &canvas)

指定されたcanvas の浅いコピーをこのキャンバスに割り当て、このキャンバスへの参照を返します。浅いコピーに関する詳細については、暗黙的なデータ共有に関するドキュメントを参照してください。

注: 基盤となる リソース(QRhiTexture などのグラフィックスリソース)は 、決してコピーされたり複製されたりすることはありません。

関連する非メンバー

[noexcept] bool operator!=(const QCanvasOffscreenCanvas &lhs, const QCanvasOffscreenCanvas &rhs)

キャンバスハンドル `lhs ` が `rhs` と異なる場合は `true ` を返し、それ以外の場合は `false ` を返します。

operator==()も参照してください 。

[noexcept] bool operator==(const QCanvasOffscreenCanvas &lhs, const QCanvasOffscreenCanvas &rhs)

キャンバスハンドル `lhs ` が `rhs` と等しい場合は `true ` を返し、それ以外の場合は `false ` を返します。

注:等価とは 、2つのキャンバスオブジェクトの塗りつぶし色が同じであり、かつ同じグラフィックリソースを参照していることを意味します。内容(ピクセルデータ)は比較されません。

operator!=()も参照してください 。

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