diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index a795328bdf9..dc7ecc25700 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -33,6 +33,7 @@ #include #include #include +#include #include #include @@ -2303,9 +2304,22 @@ static inline bool isSoftwareGl() } bool QWindowsWindow::handleWmPaint(HWND hwnd, UINT message, - WPARAM, LPARAM, LRESULT *result) + WPARAM wParam, LPARAM, LRESULT *result) { if (message == WM_ERASEBKGND) { // Backing store - ignored. + if (!m_firstBgDraw && QWindowsIntegration::instance()->darkModeHandling().testFlag(QWindowsApplication::DarkModeStyle)) { + // Get system background color + const QColor bgColor = QGuiApplicationPrivate::platformTheme()->palette()->color(QPalette::Window); + HBRUSH bgBrush = CreateSolidBrush(RGB(bgColor.red(), bgColor.green(), bgColor.blue())); + // Fill rectangle with system background color + RECT rc; + auto hdc = reinterpret_cast(wParam); + GetClientRect(hwnd, &rc); + FillRect(hdc, &rc, bgBrush); + DeleteObject(bgBrush); + // Brush the window with system background color only for first time + m_firstBgDraw = true; + } *result = 1; return true; } diff --git a/src/plugins/platforms/windows/qwindowswindow.h b/src/plugins/platforms/windows/qwindowswindow.h index 29dfbdb856b..eee13c2281c 100644 --- a/src/plugins/platforms/windows/qwindowswindow.h +++ b/src/plugins/platforms/windows/qwindowswindow.h @@ -377,6 +377,7 @@ private: HICON m_iconBig = nullptr; void *m_surface = nullptr; int m_savedDpi = 96; + bool m_firstBgDraw = false; static bool m_screenForGLInitialized;