このページでは

QPicture Class

QPicture クラスは、QPainter コマンドを記録・再生する描画デバイスです。詳細...

ヘッダー: #include <QPicture>
CMake: find_package(Qt6 REQUIRED COMPONENTS Gui)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
継承元: QPaintDevice

パブリック関数

QPicture(int formatVersion = -1)
QPicture(const QPicture &pic)
virtual ~QPicture()
QRect boundingRect() const
const char *data() const
bool isNull() const
bool load(const QString &fileName)
bool load(QIODevice *dev)
bool play(QPainter *painter)
bool save(const QString &fileName)
bool save(QIODevice *dev)
void setBoundingRect(const QRect &r)
virtual void setData(const char *data, uint size)
uint size() const
void swap(QPicture &other)
QPicture &operator=(QPicture &&other)
QPicture &operator=(const QPicture &p)
QDataStream &operator<<(QDataStream &s, const QPicture &r)
QDataStream &operator>>(QDataStream &s, QPicture &r)

詳細な説明

ピクチャーは、ペインターコマンドをプラットフォームに依存しない形式で IO デバイスにシリアル化します。これらは、メタファイルと呼ばれることもあります。

Qt のピクチャーは、独自のバイナリ形式を使用しています。多くのウィンドウシステムにおけるネイティブなピクチャー(メタファイル)形式とは異なり、Qt のピクチャーには内容に関する制限がありません。ウィジェットやピクマップ上に描画できるもの(フォント、ピクマップ、領域、変形されたグラフィックなど)はすべて、ピクチャーにも保存することができます。

QPictureは解像度に依存しません。つまり、QPictureは異なるデバイス(例えば、svg、pdf、ps、プリンタ、画面など)上で、同じ外観で表示することができます。これは、例えばWYSIWYGの印刷プレビューなどに必要です。 QPictureはシステムのデフォルトDPIで動作し、ウィンドウシステムに応じて解像度の違いに合わせて描画をスケーリングします。

画像の記録方法の例:

QPicture picture;
QPainter painter;
painter.begin(&picture);           // paint in picture
painter.drawEllipse(10,20, 80,70); // draw an ellipse
painter.end();                     // painting done
picture.save("drawing.pic");       // save picture

QPainter::begin() 関数を呼び出すたびに、ペインターコマンドのリストがリセットされる点に注意してください。

画像の再生例:

QPicture picture;
picture.load("drawing.pic");           // load picture
QPainter painter;
painter.begin(&myImage);               // paint in myImage
painter.drawPicture(0, 0, picture);    // draw the picture at (0,0)
painter.end();                         // painting done

play() を使用して画像を描画することもできます。画像に関する基本的なデータも利用可能で、例えば、size()、isNull()、boundingRect() などがあります。

注:QPictureは シリアライズにQDataStream を使用します。信頼できないデータの読み取りに関するsame reservations が適用されます。

QMovieも参照してください 。

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

[explicit] QPicture::QPicture(int formatVersion = -1)

空のピクチャーを作成します。

formatVersion パラメータを使用すると、以前のバージョンのQtでコンパイルされたアプリケーションでも読み取れるQPictureを作成できます。

なお、デフォルトの formatVersion は -1 であり、これは現在のリリースを意味します。つまり、Qt 4.0 の場合、formatVersion 7 はデフォルトの formatVersion -1 と同じです。

Qt 4.0 では、以前のバージョンの Qt で生成された画像の読み込みはサポートされていません。

QPicture::QPicture(const QPicture &pic)

pic のコピーを作成します。

このコンストラクタは、暗黙の共有のおかげで高速に動作します。

[virtual noexcept] QPicture::~QPicture()

絵の雰囲気を台無しにしてしまう。

QRect QPicture::boundingRect() const

画像の境界矩形を返します。画像にデータが含まれていない場合は、無効な矩形を返します。

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

const char *QPicture::data() const

画像データへのポインタを返します。このポインタは、この画像に対して次に非const関数が呼び出されるまで有効です。画像にデータが含まれていない場合、返されるポインタは0になります。

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

bool QPicture::isNull() const

画像にデータが含まれていない場合は `true ` を返し、それ以外の場合は `false` を返します。

bool QPicture::load(const QString &fileName)

fileName で指定されたファイルから画像を読み込み、成功した場合は true を返します。失敗した場合は、画像を無効化し、false を返します。

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

bool QPicture::load(QIODevice *dev)

dev 読み込みに使用するデバイスです。

これはオーバーロードされた関数です。

bool QPicture::play(QPainter *painter)

painter を使用して画像を再生し、成功した場合はtrue を返し、失敗した場合はfalse を返します。

この関数は、(x, y) = (0, 0) を指定した場合の `QPainter::drawPicture()` とまったく同じ動作をします。

注: この関数では、ペインターの状態は 保持されません。

bool QPicture::save(const QString &fileName)

fileName で指定されたファイルに画像を保存し、成功した場合は true を返します。失敗した場合はfalse を返します。

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

bool QPicture::save(QIODevice *dev)

dev 保存に使用するデバイスです。

これはオーバーロードされた関数です。

void QPicture::setBoundingRect(const QRect &r)

画像のバウンディング矩形を `r` に設定します。自動的に計算された値は上書きされます。

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

[virtual] void QPicture::setData(const char *data, uint size)

data およびsize から直接画像データを設定します。この関数は入力データをコピーします。

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

uint QPicture::size() const

画像データのサイズを返します。

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

[noexcept] void QPicture::swap(QPicture &other)

この画像をother と入れ替えます。この操作は非常に高速で、失敗することはありません。

[noexcept] QPicture &QPicture::operator=(QPicture &&other)

other をこのQPicture インスタンスに割り当てます。

QPicture &QPicture::operator=(const QPicture &p)

この画像に画像p を割り当て、この画像への参照を返します。

関連する非メンバー

QDataStream &operator<<(QDataStream &s, const QPicture &r)

画像 `r ` をストリーム `s ` に書き込み、そのストリームへの参照を返します。

QDataStream &operator>>(QDataStream &s, QPicture &r)

ストリーム `s ` から画像を読み込み、画像 `r ` に格納し、ストリームへの参照を返します。

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