From ab76593f18396e693f24066592244ca95e135ea2 Mon Sep 17 00:00:00 2001 From: Chris Colbert Date: Mon, 18 Nov 2013 21:49:21 -0500 Subject: [PATCH] Fix the ignored Qt::WA_StaticContents on Windows This restores the ability from the Qt 4.x series to honor the static contents region in the backbuffer when resizing a widget. The fix only applies when running under Windows. Task-number: QTBUG-34799 [ChangeLog][QtWidgets][Windows] Update QWidgetBackingStore and QWindowsBackingStore to support Qt::WA_StaticContents QWidgetBackingStore::staticContents() was updated for windows to *not* unconditionally return false. It now returns true if it has a non-empty static widgets list. QWindowsBackingStore::resize(...) was updated to honor the provided static contents region. It now copies the static region into the new backbuffer in a manner similar to what was done in Qt4. The difference is that this version accounts for the possibility of the new buffer having a smaller region than the old buffer. In Qt4 the ::prepareBuffer method was only called when the buffer was resized larger. Change-Id: I135ff8fb16f52759089f1e7353426303c4504db3 Reviewed-by: Gunnar Sletta --- .../platforms/windows/qwindowsbackingstore.cpp | 18 +++++++++++++++++- src/widgets/kernel/qwidgetbackingstore_p.h | 8 +++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowsbackingstore.cpp b/src/plugins/platforms/windows/qwindowsbackingstore.cpp index 26205eb1462..55e7b85d960 100644 --- a/src/plugins/platforms/windows/qwindowsbackingstore.cpp +++ b/src/plugins/platforms/windows/qwindowsbackingstore.cpp @@ -149,7 +149,23 @@ void QWindowsBackingStore::resize(const QSize &size, const QRegion ®ion) QImage::Format format = QWindowsNativeImage::systemFormat(); if (format == QImage::Format_RGB32 && rasterWindow()->window()->format().hasAlpha()) format = QImage::Format_ARGB32_Premultiplied; - m_image.reset(new QWindowsNativeImage(size.width(), size.height(), format)); + + QWindowsNativeImage *oldwni = m_image.data(); + QWindowsNativeImage *newwni = new QWindowsNativeImage(size.width(), size.height(), format); + + if (oldwni && !region.isEmpty()) { + const QImage &oldimg(oldwni->image()); + QImage &newimg(newwni->image()); + QRegion staticRegion(region); + staticRegion &= QRect(0, 0, oldimg.width(), oldimg.height()); + staticRegion &= QRect(0, 0, newimg.width(), newimg.height()); + QPainter painter(&newimg); + painter.setCompositionMode(QPainter::CompositionMode_Source); + foreach (const QRect &rect, staticRegion.rects()) + painter.drawImage(rect, oldimg, rect); + } + + m_image.reset(newwni); } } diff --git a/src/widgets/kernel/qwidgetbackingstore_p.h b/src/widgets/kernel/qwidgetbackingstore_p.h index 39583c8caa0..b6c3e13cb0c 100644 --- a/src/widgets/kernel/qwidgetbackingstore_p.h +++ b/src/widgets/kernel/qwidgetbackingstore_p.h @@ -240,7 +240,13 @@ private: } inline bool hasStaticContents() const - { return !staticWidgets.isEmpty() && false; } + { +#if defined(Q_OS_WIN) + return !staticWidgets.isEmpty(); +#else + return !staticWidgets.isEmpty() && false; +#endif + } friend QRegion qt_dirtyRegion(QWidget *); friend class QWidgetPrivate;