@@ -111,6 +111,17 @@ static QRect spinboxIndicatorRect(const QRect &r)
111
111
return QRect (xOffset, yOffset, size, size);
112
112
}
113
113
114
+ // the object is the class's instance.
115
+ template <class T >
116
+ inline static bool isTheClassObject (QObject *object)
117
+ {
118
+ #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
119
+ return object->metaObject ()->className () == T::staticMetaObject.className ();
120
+ #else
121
+ return object->metaObject ()->metaType () == T::staticMetaObject.metaType ();
122
+ #endif
123
+ }
124
+
114
125
ChameleonStyle::ChameleonStyle ()
115
126
: DStyle()
116
127
{
@@ -208,9 +219,9 @@ void ChameleonStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOpti
208
219
209
220
// QTreeView的绘制复制了QCommonStyle的代码,添加了圆角的处理,hover的处理
210
221
if (qobject_cast<const QTreeView *>(w)) {
211
- const auto & delegate = * qobject_cast<const QTreeView *>(w)->itemDelegate ();
222
+ const auto delegate = qobject_cast<const QTreeView *>(w)->itemDelegate ();
212
223
// 如果QTreeView使用的不是默认代理 QStyledItemDelegate,则采取DStyle的默认绘制(备注:这里的QtCreator不会有hover效果和圆角)
213
- if (typeid (delegate) != typeid ( QStyledItemDelegate)) {
224
+ if (!isTheClassObject< QStyledItemDelegate>(delegate )) {
214
225
break ;
215
226
}
216
227
@@ -576,9 +587,9 @@ void ChameleonStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOpti
576
587
}
577
588
// 这里QTreeView的绘制复制了QCommonStyle的代码,添加了圆角的处理,hover的处理
578
589
if (qobject_cast<const QTreeView *>(w)) {
579
- const auto & delegate = * qobject_cast<const QTreeView *>(w)->itemDelegate ();
590
+ const auto delegate = qobject_cast<const QTreeView *>(w)->itemDelegate ();
580
591
// 如果QTreeView使用的不是默认代理 QStyledItemDelegate,则采取DStyle的默认绘制(备注:这里的QtCreator不会有hover效果和圆角)
581
- if (typeid (delegate) != typeid ( QStyledItemDelegate)) {
592
+ if (!isTheClassObject< QStyledItemDelegate>(delegate )) {
582
593
break ;
583
594
}
584
595
0 commit comments