path: root/src/gui/painting/qpainter.cpp
diff options
authorMorten Johan Sørvig <>2015-02-24 11:13:31 +0100
committerMorten Johan Sørvig <>2018-04-26 10:39:25 +0000
commit7160df3a15637acbb6548878d3a0afe294e64a6b (patch)
treee542d6ff36a3ff5fe43d50dd5adc255f7337fca3 /src/gui/painting/qpainter.cpp
parenta9fc91466c2c143bea422d98af24755f43c2b97b (diff)
High-dpi drawTiledPixmap (raster paint engine)
Implement more consistent behavior for drawTiledPixmap(), which should produce the same visual tiling pattern independent of display devicePixelRatio Consider the following pixmaps and draw calls: QPixmap px32; // 32x32 QPixmap px64; // 64x64 drawTiledPixmap(QRect(0, 0, 128, 128), px32); drawTiledPixmap(QRect(0, 0, 128, 128), px64); On 1x displays this will produce 4x4 and 2x2 tiles, respectively. On 2x displays this would previously produce a different tiling pattern, where the paint engine would tile in the device pixel coordinate system. Change this to tile in the device independent coordinate system, producing the same visual tiling pattern as the 1x case. It is possible to produce a 4x4 tiling pattern with high-resolution output from the 64x64 pixmap by setting the devicePixelRatio: QPixmap px64; px64.setDevicePixelRatio(2); drawTiledPixmap(QRect(0, 0, 128, 128), px64); This change adds an inverse scale to the image filler transform that accounts for the pixmap devicePixelRatio. [ChangeLog][QtGui] QPainter::drawTiledPixmap() now tiles in the device independent coordinate system. Change-Id: I4918d274192967f222f181b374571c7c597dcd76 Reviewed-by: Jonathan Courtois <> Reviewed-by: Timur Pocheptsov <> Reviewed-by: 石博文 <> Reviewed-by: Eirik Aavitsland <>
Diffstat (limited to 'src/gui/painting/qpainter.cpp')
1 files changed, 10 insertions, 0 deletions
diff --git a/src/gui/painting/qpainter.cpp b/src/gui/painting/qpainter.cpp
index a0a58cc157..a37511ff0a 100644
--- a/src/gui/painting/qpainter.cpp
+++ b/src/gui/painting/qpainter.cpp
@@ -6664,6 +6664,16 @@ QRectF QPainter::boundingRect(const QRectF &r, const QString &text, const QTextO
potentially much more efficient depending on the underlying window
+ drawTiledPixmap() will produce the same visual tiling pattern on
+ high-dpi displays (with devicePixelRatio > 1), compared to normal-
+ dpi displays. Set the devicePixelRatio on the \a pixmap to control
+ the tile size. For example, setting it to 2 halves the tile width
+ and height (on both 1x and 2x displays), and produces high-resolution
+ output on 2x displays.
+ The \a position offset is always in the painter coordinate system,
+ indepentent of display devicePixelRatio.
\sa drawPixmap()
void QPainter::drawTiledPixmap(const QRectF &r, const QPixmap &pixmap, const QPointF &sp)