diff options
author | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-11-03 17:17:44 +0100 |
---|---|---|
committer | Richard Moe Gustavsen <richard.gustavsen@qt.io> | 2020-11-04 09:49:48 +0100 |
commit | e5dfa302fe227576aece1d5637251ac68ead0374 (patch) | |
tree | 0d714ad925c963f5d909a4be83d6f14a1079f3cf /src/imports | |
parent | cde1a8a10b611e3e3cf048ec1b108c031ef1b2a9 (diff) |
QQuickStyleItem: reuse QImage when painting, if possible
If the size of the QImage we draw on hasn't changed between
subsequent calls to paintControlToImage, we can just
reuse the one we already got. This way we avoid creating
and throwing away images unnecessary.
Change-Id: Icf65bb8d9008a21e7114e588df46bc1e4cbdea97
Reviewed-by: Jan Arve Sæther <jan-arve.saether@qt.io>
Diffstat (limited to 'src/imports')
-rw-r--r-- | src/imports/nativestyle/items/qquickstyleitem.cpp | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/src/imports/nativestyle/items/qquickstyleitem.cpp b/src/imports/nativestyle/items/qquickstyleitem.cpp index 506392cb..9f6ce676 100644 --- a/src/imports/nativestyle/items/qquickstyleitem.cpp +++ b/src/imports/nativestyle/items/qquickstyleitem.cpp @@ -284,8 +284,13 @@ void QQuickStyleItem::paintControlToImage() m_dirty.setFlag(DirtyFlag::Image, false); const qreal scale = window()->devicePixelRatio(); - m_paintedImage = QImage(imageSize() * scale, QImage::Format_ARGB32_Premultiplied); - m_paintedImage.setDevicePixelRatio(scale); + const QSize scaledImageSize = imageSize() * scale; + + if (m_paintedImage.size() != scaledImageSize) { + m_paintedImage = QImage(scaledImageSize, QImage::Format_ARGB32_Premultiplied); + m_paintedImage.setDevicePixelRatio(scale); + } + m_paintedImage.fill(Qt::transparent); QPainter painter(&m_paintedImage); |