diff options
author | Morten Johan Sørvig <morten.sorvig@qt.io> | 2021-02-21 20:46:22 +0100 |
---|---|---|
committer | Volker Hilsheimer <volker.hilsheimer@qt.io> | 2021-03-08 08:27:41 +0000 |
commit | 1471f2ae0924e5d124178d1953a14db889348da0 (patch) | |
tree | def325a49c4caced38619631008b2ccc62c02967 /src/gui/image/qpixmap.cpp | |
parent | 4f37cf2ce544dad5b207161536566627b6b0b1ef (diff) |
Add deviceIndependentSize() to QPixmap and QImage
This function returns the size in device independent
pixels, and should be used when calculating user
interface sizes.
Change-Id: I528123f962595a3da42438ca560289a29aca4917
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Diffstat (limited to 'src/gui/image/qpixmap.cpp')
-rw-r--r-- | src/gui/image/qpixmap.cpp | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/gui/image/qpixmap.cpp b/src/gui/image/qpixmap.cpp index d8473001aa..2f9c4fd617 100644 --- a/src/gui/image/qpixmap.cpp +++ b/src/gui/image/qpixmap.cpp @@ -633,7 +633,7 @@ qreal QPixmap::devicePixelRatio() const high-DPI pixmap rather than a large pixmap (see \l{Drawing High Resolution Versions of Pixmaps and Images}). - \sa devicePixelRatio() + \sa devicePixelRatio(), devicePixelSize() */ void QPixmap::setDevicePixelRatio(qreal scaleFactor) { @@ -647,6 +647,21 @@ void QPixmap::setDevicePixelRatio(qreal scaleFactor) data->setDevicePixelRatio(scaleFactor); } +/*! + Returns the size of the pixmap in device independent pixels. + + This value should be used when using the pixmap size in user interface + size calculations. + + The return value is equivalent to pixmap.size() / pixmap.devicePixelRatio(), +*/ +QSizeF QPixmap::deviceIndependentSize() const +{ + if (!data) + return QSizeF(0, 0); + return QSizeF(data->width(), data->height()) / data->devicePixelRatio(); +} + #ifndef QT_NO_IMAGE_HEURISTIC_MASK /*! Creates and returns a heuristic mask for this pixmap. |