From 5641db1f9f342eec3755726d732c31a35cd1070e Mon Sep 17 00:00:00 2001 From: Wladimir Leuschner Date: Mon, 24 Feb 2025 15:25:40 +0100 Subject: [PATCH] WindowsQPA: Add default icon to custom titlebar MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit In case that no application icon was provided, use the IDI_APPLICATION icon when Qt::WindowTitleHint was provided. Fixes: QTBUG-133941 Change-Id: Ifb479a7056e0841215d525c2346938bda31fc1c6 Reviewed-by: Tor Arne Vestbø Reviewed-by: Oliver Wolff (cherry picked from commit 92a14cdc36c4b2c30e4c7dfe7568b1835cb63093) Reviewed-by: Qt Cherry-pick Bot --- .../platforms/windows/qwindowswindow.cpp | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/plugins/platforms/windows/qwindowswindow.cpp b/src/plugins/platforms/windows/qwindowswindow.cpp index 84dfeb0dcd5..76e583a7331 100644 --- a/src/plugins/platforms/windows/qwindowswindow.cpp +++ b/src/plugins/platforms/windows/qwindowswindow.cpp @@ -3500,9 +3500,8 @@ void QWindowsWindow::updateCustomTitlebar() p.setPen(Qt::NoPen); if (!wnd->flags().testFlags(Qt::NoTitleBarBackgroundHint)) { QRect titleRect; - titleRect.setY(1); titleRect.setX(2); - titleRect.setWidth(windowWidth - 2); + titleRect.setWidth(windowWidth); titleRect.setHeight(titleBarHeight); if (isWindows11orAbove) { @@ -3529,13 +3528,19 @@ void QWindowsWindow::updateCustomTitlebar() titleRect.setWidth(windowWidth); titleRect.setHeight(titleBarHeight); - const QIcon icon = wnd->icon(); - if (!icon.isNull()) { - titleRect.adjust(factor * 4, 0, 0, 0); - QRect iconRect(titleRect.x(), titleRect.y() + factor * 8, factor * 16, factor * 16); - icon.paint(&p, iconRect); - titleRect.adjust(factor * 24, 0, 0, 0); + titleRect.adjust(factor * 4, 0, 0, 0); + QRect iconRect(titleRect.x(), titleRect.y() + factor * 8, factor * 16, factor * 16); + if (wnd->icon().isNull()) { + static QIcon defaultIcon; + if (defaultIcon.isNull()) { + const QImage defaultIconImage = QImage::fromHICON(LoadIcon(0, IDI_APPLICATION)); + defaultIcon = QIcon(QPixmap::fromImage(defaultIconImage)); + } + defaultIcon.paint(&p, iconRect); + } else { + wnd->icon().paint(&p, iconRect); } + titleRect.adjust(factor * 24, 0, 0, 0); p.setPen(textPen); QFont titleFont = QWindowsIntegration::instance()->fontDatabase()->defaultFont();