From 5565d2089b7d36d38852668d5aae43f22d6b008b Mon Sep 17 00:00:00 2001 From: Ye ShanShan Date: Fri, 17 May 2024 11:34:54 +0800 Subject: [PATCH] fix: qapitrace open file crash it's same as b80e65a4f15d3b505324c0daf2acde6a76efceb6 --- styleplugins/chameleon/chameleonstyle.cpp | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/styleplugins/chameleon/chameleonstyle.cpp b/styleplugins/chameleon/chameleonstyle.cpp index d28a723a..95cb2f8c 100644 --- a/styleplugins/chameleon/chameleonstyle.cpp +++ b/styleplugins/chameleon/chameleonstyle.cpp @@ -111,6 +111,17 @@ static QRect spinboxIndicatorRect(const QRect &r) return QRect(xOffset, yOffset, size, size); } +// the object is the class's instance. +template +inline static bool isTheClassObject(QObject *object) +{ +#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) + return object->metaObject()->className() == T::staticMetaObject.className(); +#else + return object->metaObject()->metaType() == T::staticMetaObject.metaType(); +#endif +} + ChameleonStyle::ChameleonStyle() : DStyle() { @@ -208,9 +219,9 @@ void ChameleonStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOpti //QTreeView的绘制复制了QCommonStyle的代码,添加了圆角的处理,hover的处理 if (qobject_cast(w)) { - const auto &delegate = *qobject_cast(w)->itemDelegate(); + const auto delegate = qobject_cast(w)->itemDelegate(); //如果QTreeView使用的不是默认代理 QStyledItemDelegate,则采取DStyle的默认绘制(备注:这里的QtCreator不会有hover效果和圆角) - if (typeid(delegate) != typeid(QStyledItemDelegate)) { + if (!isTheClassObject(delegate)) { break; } @@ -576,9 +587,9 @@ void ChameleonStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOpti } //这里QTreeView的绘制复制了QCommonStyle的代码,添加了圆角的处理,hover的处理 if (qobject_cast(w)) { - const auto &delegate = *qobject_cast(w)->itemDelegate(); + const auto delegate = qobject_cast(w)->itemDelegate(); //如果QTreeView使用的不是默认代理 QStyledItemDelegate,则采取DStyle的默认绘制(备注:这里的QtCreator不会有hover效果和圆角) - if (typeid(delegate) != typeid(QStyledItemDelegate)) { + if (!isTheClassObject(delegate)) { break; }