qtutils: implement parent finder

This commit is contained in:
itsmattkc
2022-07-22 17:33:31 -07:00
parent 3fab456816
commit a3cde5bd44
2 changed files with 17 additions and 10 deletions
+15
View File
@@ -64,6 +64,21 @@ public:
static QStringList WordWrapString(const QString &s, const QFontMetrics &fm, int bounding_width);
template <typename T>
static T *GetParentOfType(const QObject *child)
{
QObject *t = child->parent();
while (t) {
if (T *p = dynamic_cast<T*>(t)) {
return p;
}
t = t->parent();
}
return nullptr;
}
};
}