QPaintDevice Class
QPaintDevice クラスは、QPainter を使用して描画可能なオブジェクトの基底クラスです。詳細...
| ヘッダー: | #include <QPaintDevice> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
| 継承元: | QImage、QOpenGLPaintDevice 、QPagedPaintDevice 、QPaintDeviceWindow 、QPicture 、QPixmap 、QSvgGenerator 、およびQWidget |
- 継承されたメンバーを含むすべてのメンバーの一覧
- QPaintDevice は、Painting クラスの一部です。
パブリック型
| enum | PaintDeviceMetric { PdmWidth, PdmHeight, PdmWidthMM, PdmHeightMM, PdmNumColors, …, PdmDevicePixelRatioF_EncodedB } |
パブリック関数
| virtual | ~QPaintDevice() |
| int | colorCount() const |
| int | depth() const |
| qreal | devicePixelRatio() const |
| qreal | devicePixelRatioF() const |
| int | height() const |
| int | heightMM() const |
| int | logicalDpiX() const |
| int | logicalDpiY() const |
| virtual QPaintEngine * | paintEngine() const = 0 |
| bool | paintingActive() const |
| int | physicalDpiX() const |
| int | physicalDpiY() const |
| int | width() const |
| int | widthMM() const |
静的パブリックメンバー
(since 6.8) int | encodeMetricF(QPaintDevice::PaintDeviceMetric metric, double value) |
Protected 関数
| QPaintDevice() | |
| virtual int | metric(QPaintDevice::PaintDeviceMetric metric) const |
詳細な説明
ペイントデバイスは、QPainter を使用して描画できる 2 次元空間の抽象化です。そのデフォルトの座標系の原点は左上に位置しています。X 座標は右に向かって増加し、Y 座標は下に向かって増加します。単位は 1 ピクセルです。
QPaintDeviceの描画機能は、現在、QWidget 、QImage 、QPixmap 、QPicture 、およびQPrinter の各サブクラスによって実装されています。
新しいバックエンドのサポートを実装するには、QPaintDevice を継承し、仮想関数paintEngine() を再実装して、この特定のデバイス上で描画するためにどのペイントエンジンを使用すべきかをQPainter に指定する必要があります。なお、デバイス上で描画を行うには、対応するペイントエンジンを作成する必要がある点に注意してください。つまり、QPaintEngine を継承し、その仮想関数を再実装する必要があります。
警告: Qt では、ペイントデバイスを作成する前に、QGuiApplication オブジェクトが存在している必要があります。ペイントデバイスはウィンドウシステムのリソースにアクセスしますが、これらのリソースはアプリケーションオブジェクトが作成されるまでは初期化されません。
QPaintDevice クラスは、さまざまなデバイスメトリクスを返すいくつかの関数を提供しています。depth() 関数は、そのビット深度(ビットプレーンの数)を返します。height() 関数は、デフォルトの座標系単位(QPixmap やQWidget の場合、ピクセルなど)での高さを返し、heightMM() はデバイスの高さをミリメートル単位で返します。 同様に、width() 関数とwidthMM() 関数は、それぞれデフォルトの座標系単位およびミリメートル単位でデバイスの幅を返します。あるいは、保護されたmetric() 関数を使用し、引数として目的のPaintDeviceMetric を指定することで、メトリック情報を取得することもできます。
logicalDpiX() およびlogicalDpiY() 関数は、デバイスの水平および垂直解像度をドット/インチ単位で返します。physicalDpiX() およびphysicalDpiY() 関数も同様に、デバイスの解像度をドット/インチ単位で返しますが、論理解像度と物理解像度が異なる場合、対応するQPaintEngine がそのマッピングを処理する必要があることに注意してください。 最後に、colorCount() 関数は、ペイントデバイスで使用可能な異なる色の数を返します。
「 QPaintEngine」 、「QPainter 」、「座標系」、「ペイントシステム」も参照してください 。
メンバ型のドキュメント
enum QPaintDevice::PaintDeviceMetric
ペイントデバイスのさまざまなメトリクスについて説明します。
| 定数 | 値 | 説明 |
|---|---|---|
QPaintDevice::PdmWidth | 1 | デフォルトの座標系単位でのペイントデバイスの幅(例:QPixmap およびQWidget ではピクセル)。width() も参照してください。 |
QPaintDevice::PdmHeight | 2 | デフォルトの座標系単位でのペイントデバイスの高さ(例:QPixmap およびQWidget ではピクセル)。height() も参照してください。 |
QPaintDevice::PdmWidthMM | 3 | ペイントデバイスの幅(ミリメートル単位)。widthMM() も参照してください。 |
QPaintDevice::PdmHeightMM | 4 | ペイントデバイスの高さ(単位:ミリメートル)。heightMM() も参照してください。 |
QPaintDevice::PdmNumColors | 5 | ペイントデバイスで使用可能な異なる色の数。colorCount() も参照してください。 |
QPaintDevice::PdmDepth | 6 | ペイントデバイスのビット深度(ビットプレーンの数)。depth() も参照してください。 |
QPaintDevice::PdmDpiX | 7 | デバイスの水平解像度(ドット/インチ)。logicalDpiX() も参照してください。 |
QPaintDevice::PdmDpiY | 8 | デバイスの垂直解像度(ドット/インチ)。logicalDpiY() も参照してください。 |
QPaintDevice::PdmPhysicalDpiX | 9 | デバイスの水平解像度(ドット/インチ)。physicalDpiX() も参照してください。 |
QPaintDevice::PdmPhysicalDpiY | 10 | デバイスの垂直解像度(ドット/インチ)。physicalDpiY() も参照してください。 |
QPaintDevice::PdmDevicePixelRatio | 11 | デバイスのデバイス・ピクセル比。一般的な値として、通常 DPI のディスプレイでは 1、高 DPI の「Retina」ディスプレイでは 2 となります。 |
QPaintDevice::PdmDevicePixelRatioScaled | 12 | デバイスのスケーリング済みデバイス・ピクセル比。これは PdmDevicePixelRatio と同一ですが、小数スケール係数を持つペイント・デバイスをサポートするために、値が一定の倍率でスケーリングされている点が異なります。使用される定数スケーリング係数は devicePixelRatioFScale() です。この列挙型値は Qt 5.6 で導入されました。 |
QPaintDevice::PdmDevicePixelRatioF_EncodedA (since Qt 6.8) | 13 | この列挙項目は、対応するB 項目とともに、デバイスのデバイス・ピクセル比を表すエンコードされたdouble 浮動小数点値として使用されます。小数点のDPR値をサポートするQPaintDevice のサブクラスは、metric()関数のオーバーライドにおいて、これら2つの列挙項目のサポートを実装する必要があります。戻り値は、encodeMetricF()関数の結果となることが想定されています。 |
QPaintDevice::PdmDevicePixelRatioF_EncodedB (since Qt 6.8) | 14 | PdmDevicePixelRatioF_EncodedAを参照してください。 |
metric() およびdevicePixelRatio()も参照してください 。
メンバ関数のドキュメント
[noexcept protected] QPaintDevice::QPaintDevice()
ペイントデバイスを生成します。このコンストラクタは、QPaintDevice のサブクラスからのみ呼び出すことができます。
[virtual noexcept] QPaintDevice::~QPaintDevice()
ペイントデバイスを破棄し、ウィンドウシステムのリソースを解放します。
int QPaintDevice::colorCount() const
ペイントデバイスで使用可能な異なる色の数を返します。使用可能な色の数が多すぎて int データ型で表現できない場合は、代わりに INT_MAX が返されます。
int QPaintDevice::depth() const
ペイントデバイスのビット深度(ビットプレーンの数)を返します。
qreal QPaintDevice::devicePixelRatio() const
指定されたデバイスのデバイス・ピクセル比を返します。
一般的な値として、標準DPIのディスプレイでは1、高DPIの「Retina」ディスプレイでは2となります。
qreal QPaintDevice::devicePixelRatioF() const
そのデバイスのデバイス・ピクセル比を浮動小数点数として返します。
[static, since 6.8] int QPaintDevice::encodeMetricF(QPaintDevice::PaintDeviceMetric metric, double value)
メトリック `metric` に対してエンコードされた `value ` を返します。metric() を実装するサブクラスは、この関数を使用してエンコードを行う必要があります
| 定数 | 説明 |
|---|---|
as | クエリメトリックがエンコードされた浮動小数点値を指定する場合、整数の戻り値をエンコードするためにこの関数を使用する必要があります。 |
この関数は Qt 6.8 で導入されました。
int QPaintDevice::height() const
デフォルトの座標系単位(例:QPixmap やQWidget ではピクセル)で、ペイントデバイスの高さを返します。
heightMM()も参照してください 。
int QPaintDevice::heightMM() const
ペイントデバイスの高さをミリメートル単位で返します。プラットフォームの制限により、この関数を使用して画面上のウィジェットの実際の物理的なサイズを特定できない場合があります。
height()も参照してください 。
int QPaintDevice::logicalDpiX() const
デバイスの水平解像度をドット/インチ単位で返します。これはフォントサイズの計算に使用されます。X11の場合、これは通常、widthMM() から算出される値と同じです。
logicalDpiX() の値がphysicalDpiX() の値と等しくない場合、対応するQPaintEngine が解像度のマッピングを処理する必要があることに注意してください。
logicalDpiY() およびphysicalDpiX()も参照してください 。
int QPaintDevice::logicalDpiY() const
デバイスの垂直解像度をドット/インチ単位で返します。これはフォントサイズの計算に使用されます。X11の場合、これは通常、heightMM() から算出される値と同じになります。
logicalDpiY() の値がphysicalDpiY() の値と一致しない場合、対応するQPaintEngine が解像度のマッピングを処理する必要があることに注意してください。
logicalDpiX() およびphysicalDpiY()も参照してください 。
[virtual protected] int QPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
指定されたペイントデバイス `metric` のメトリック情報を返します。
「PaintDeviceMetric」も参照してください 。
[pure virtual] QPaintEngine *QPaintDevice::paintEngine() const
デバイスへの描画に使用されるペイントエンジンへのポインタを返します。
bool QPaintDevice::paintingActive() const
デバイスが現在描画中である場合(つまり、このデバイスに対してQPainter::begin()が呼び出されているが、QPainter::end()はまだ呼び出されていない場合)、true を返します。それ以外の場合はfalse を返します。
QPainter::isActive()も参照してください 。
int QPaintDevice::physicalDpiX() const
デバイスの水平解像度をドット/インチ(dpi)単位で返します。たとえば、印刷時には、この解像度はプリンタの物理的な解像度を指します。一方、論理DPIとは、実際の描画エンジンで使用される解像度を指します。
physicalDpiX() の値がlogicalDpiX() の値と等しくない場合、対応するQPaintEngine が解像度のマッピングを処理する必要があることに注意してください。
physicalDpiY() およびlogicalDpiX()も参照してください 。
int QPaintDevice::physicalDpiY() const
デバイスの水平解像度をドット/インチ(dpi)単位で返します。たとえば、印刷時には、この解像度はプリンタの物理的な解像度を指します。一方、論理DPIとは、実際の描画エンジンで使用される解像度を指します。
なお、physicalDpiY() の値がlogicalDpiY() の値と一致しない場合、対応するQPaintEngine は解像度のマッピングを処理する必要があります。
physicalDpiX() およびlogicalDpiY()も参照してください 。
int QPaintDevice::width() const
デフォルトの座標系単位(例:QPixmap やQWidget ではピクセル)で、ペイントデバイスの幅を返します。
widthMM()も参照してください 。
int QPaintDevice::widthMM() const
ペイントデバイスの幅をミリメートル単位で返します。プラットフォームの制限により、この関数を使用して画面上のウィジェットの実際の物理的なサイズを特定できない場合があります。
width()も参照してください 。
© 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.