WindowsQPA: Add default icon to custom titlebar

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ø <tor.arne.vestbo@qt.io>
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 92a14cdc36c4b2c30e4c7dfe7568b1835cb63093)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Wladimir Leuschner 2025-02-24 15:25:40 +01:00 committed by Qt Cherry-pick Bot
parent 0159e662ee
commit 5641db1f9f

View File

@ -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();