diff options
author | Thomas Hartmann <thomas.hartmann@qt.io> | 2020-11-25 12:25:24 +0100 |
---|---|---|
committer | Thomas Hartmann <thomas.hartmann@qt.io> | 2020-11-25 13:17:15 +0000 |
commit | 9939b1844d58b6f032926babddd278296e055557 (patch) | |
tree | 81cc97782e672b13f658a9c733a317e92111babb | |
parent | 35c2d51ec9ac4a1b52d2a6626083162839bb84b6 (diff) |
Fix crash in ManhattanStyle
The widget can be a nullptr.
const bool isComboBox = widget->inherits("QComboBox");
Was crashing in the iso icon browser.
Task-number: QDS-3079
Change-Id: Ie7efa08ff5be094b94a835db895929158918bfcf
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
-rw-r--r-- | src/plugins/coreplugin/manhattanstyle.cpp | 12 |
1 files changed, 7 insertions, 5 deletions
diff --git a/src/plugins/coreplugin/manhattanstyle.cpp b/src/plugins/coreplugin/manhattanstyle.cpp index 5a6b80f0d6..c043b05e8a 100644 --- a/src/plugins/coreplugin/manhattanstyle.cpp +++ b/src/plugins/coreplugin/manhattanstyle.cpp @@ -431,7 +431,7 @@ static void drawPrimitiveTweakedForDarkTheme(QStyle::PrimitiveElement element, break; } case QStyle::PE_FrameLineEdit: { - const bool isComboBox = widget->inherits("QComboBox"); + const bool isComboBox = widget && widget->inherits("QComboBox"); const QRectF frameRectF = QRectF(option->rect).adjusted(0.5, 0.5, isComboBox ? -8.5 : -0.5, -0.5); painter->setPen(framePen); @@ -447,7 +447,8 @@ static void drawPrimitiveTweakedForDarkTheme(QStyle::PrimitiveElement element, // Shrinking the topMargin if Not checkable AND title is empty topMargin = groupBoxTopMargin; } else { - topMargin = qMax(widget->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight), + const int exclusiveIndicatorHeight = widget ? widget->style()->pixelMetric(QStyle::PM_ExclusiveIndicatorHeight) : 0; + topMargin = qMax(exclusiveIndicatorHeight, option->fontMetrics.height()) + groupBoxTopMargin; } // Snippet from QFusionStyle::drawPrimitive - END @@ -505,15 +506,16 @@ static void drawPrimitiveTweakedForDarkTheme(QStyle::PrimitiveElement element, break; } case QStyle::PE_IndicatorTabClose: { - QWindow *window = widget->window()->windowHandle(); + QWindow *window = widget ? widget->window()->windowHandle() : nullptr; QRect iconRect = QRect(0, 0, 16, 16); iconRect.moveCenter(option->rect.center()); const QIcon::Mode mode = !isEnabled ? QIcon::Disabled : QIcon::Normal; const static QIcon closeIcon = Utils::Icons::CLOSE_FOREGROUND.icon(); - if (option->state & QStyle::State_MouseOver) + if (option->state & QStyle::State_MouseOver && widget) widget->style()->drawPrimitive(QStyle::PE_PanelButtonCommand, option, painter, widget); + const int devicePixelRatio = widget ? widget->devicePixelRatio() : 1; const QPixmap iconPx = - closeIcon.pixmap(window, iconRect.size() * widget->devicePixelRatio(), mode); + closeIcon.pixmap(window, iconRect.size() * devicePixelRatio, mode); painter->drawPixmap(iconRect, iconPx); break; } |