From 596c9a71fa18df9490e80c4264f9e33ccae5bd70 Mon Sep 17 00:00:00 2001 From: Axel Spoerl Date: Thu, 8 Jun 2023 10:17:42 +0200 Subject: [PATCH] Don't double draw ItemViewItems' icons in QStyleSheetStyle::drawControl To draw a CE_ItemViewItem QStyleSheetStyle::drawControl lets parts of the element being drawn by QWindowsStyle, others by baseStyle(). If the ItemViewItem has an icon, it can lead to the icon being drawn twice: Once by QWindowsStyle, respecting options set in the stylesheet. Once by the baseStyle(), not respecting stylesheet options. When the style sheet modifies the icon's position, the icon will be drawn at this position as well as on the default position. This patch prevents an icon to be drawn by baseStyle() when it has already been drawn by the QWindowsStyle. Fixes: QTBUG-110942 Change-Id: I8622dfe95bef13b196a3e38025fac1cc92f097c9 Reviewed-by: Volker Hilsheimer (cherry picked from commit 30cf6ed32f3e38c8623cbafbb25b4ce558d370f3) Reviewed-by: Qt Cherry-pick Bot --- src/widgets/styles/qstylesheetstyle.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index db863dc287..06a49d8e0f 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -4393,6 +4393,11 @@ void QStyleSheetStyle::drawControl(ControlElement ce, const QStyleOption *opt, Q optIndicator.backgroundBrush = Qt::NoBrush; // no background optIndicator.text.clear(); QWindowsStyle::drawControl(ce, &optIndicator, p, w); + + // If the indicator has an icon, it has been drawn now. + // => don't draw it again. + optCopy.icon = QIcon(); + // Now draw text, background, and highlight, but not the indicator with the // base style. Since we can't turn off HasCheckIndicator to prevent the base // style from drawing the check indicator again (it would change how the item