Skip to content

Commit 70169a5

Browse files
deepin-ci-robot18202781743
authored andcommitted
sync: from linuxdeepin/qt5integration
Synchronize source files from linuxdeepin/qt5integration. Source-pull-request: linuxdeepin/qt5integration#222
1 parent b4460e2 commit 70169a5

File tree

1 file changed

+15
-4
lines changed

1 file changed

+15
-4
lines changed

styleplugins/chameleon/chameleonstyle.cpp

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ static QRect spinboxIndicatorRect(const QRect &r)
111111
return QRect(xOffset, yOffset, size, size);
112112
}
113113

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+
114125
ChameleonStyle::ChameleonStyle()
115126
: DStyle()
116127
{
@@ -208,9 +219,9 @@ void ChameleonStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOpti
208219

209220
//QTreeView的绘制复制了QCommonStyle的代码,添加了圆角的处理,hover的处理
210221
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();
212223
//如果QTreeView使用的不是默认代理 QStyledItemDelegate,则采取DStyle的默认绘制(备注:这里的QtCreator不会有hover效果和圆角)
213-
if (typeid(delegate) != typeid(QStyledItemDelegate)) {
224+
if (!isTheClassObject<QStyledItemDelegate>(delegate)) {
214225
break;
215226
}
216227

@@ -576,9 +587,9 @@ void ChameleonStyle::drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOpti
576587
}
577588
//这里QTreeView的绘制复制了QCommonStyle的代码,添加了圆角的处理,hover的处理
578589
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();
580591
//如果QTreeView使用的不是默认代理 QStyledItemDelegate,则采取DStyle的默认绘制(备注:这里的QtCreator不会有hover效果和圆角)
581-
if (typeid(delegate) != typeid(QStyledItemDelegate)) {
592+
if (!isTheClassObject<QStyledItemDelegate>(delegate)) {
582593
break;
583594
}
584595

0 commit comments

Comments
 (0)