Avoid crash with Windows 11 style when no widget passed

The documentation of `QStyle::drawControl()` states that
"The widget argument is optional" so it must not be used
unconditionally.

Change-Id: I8b5a8ed421c0ae2c667925e448c9a029b6deedfd
Reviewed-by: Oliver Wolff <oliver.wolff@qt.io>
(cherry picked from commit 30061e8960eb9d8abb8a98270e3e92beef60d7d3)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Marius Kittler 2024-04-12 10:26:33 +02:00 committed by Qt Cherry-pick Bot
parent 8baa2b73a4
commit 04fe9d0617

View File

@ -1629,7 +1629,7 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
if ((vopt->state & State_Selected || vopt->state & State_MouseOver) && !(isTreeView && vopt->state & State_MouseOver) && vopt->showDecorationSelected) {
painter->setBrush(WINUI3Colors[colorSchemeIndex][subtleHighlightColor]);
QWidget *editorWidget = view->indexWidget(view->currentIndex());
QWidget *editorWidget = view ? view->indexWidget(view->currentIndex()) : nullptr;
if (editorWidget) {
QPalette pal = editorWidget->palette();
QColor editorBgColor = vopt->backgroundBrush == Qt::NoBrush ? vopt->palette.color(widget->backgroundRole()) : vopt->backgroundBrush.color();
@ -1682,7 +1682,7 @@ void QWindows11Style::drawControl(ControlElement element, const QStyleOption *op
vopt->icon.paint(painter, iconRect, vopt->decorationAlignment, mode, state);
painter->setPen(QPen(option->palette.buttonText().color()));
if (!view->isPersistentEditorOpen(vopt->index))
if (!view || !view->isPersistentEditorOpen(vopt->index))
d->viewItemDrawText(painter, vopt, textRect);
if (vopt->state & State_Selected
&& (vopt->viewItemPosition == QStyleOptionViewItem::Beginning