aboutsummaryrefslogtreecommitdiffstats
path: root/src/imports/labsmodels/qqmldelegatecomponent.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/imports/labsmodels/qqmldelegatecomponent.cpp')
-rw-r--r--src/imports/labsmodels/qqmldelegatecomponent.cpp12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/imports/labsmodels/qqmldelegatecomponent.cpp b/src/imports/labsmodels/qqmldelegatecomponent.cpp
index 4698287fe3..aaf3fea5da 100644
--- a/src/imports/labsmodels/qqmldelegatecomponent.cpp
+++ b/src/imports/labsmodels/qqmldelegatecomponent.cpp
@@ -218,7 +218,7 @@ bool QQmlDelegateChoice::match(int row, int column, const QVariant &value) const
/*!
\qmlproperty string QtQml.Models::DelegateChooser::role
- This property holds the role used to determine the delegate for a given model item.
+ This property holds the role or the property name used to determine the delegate for a given model item.
\sa DelegateChoice
*/
@@ -289,9 +289,15 @@ QQmlComponent *QQmlDelegateChooser::delegate(QQmlAdaptorModel *adaptorModel, int
v = value(adaptorModel, row, column, m_role);
if (!v.isValid()) { // check if the row only has modelData, for example if the row is a QVariantMap
v = value(adaptorModel, row, column, QStringLiteral("modelData"));
- if (v.isValid())
- v = v.toMap().value(m_role);
+
+ if (v.isValid()) {
+ if (v.canConvert(QMetaType::QVariantMap))
+ v = v.toMap().value(m_role);
+ else if (v.canConvert(QMetaType::QObjectStar))
+ v = v.value<QObject*>()->property(m_role.toUtf8());
+ }
}
+
// loop through choices, finding first one that fits
for (int i = 0; i < m_choices.count(); ++i) {
const QQmlDelegateChoice *choice = m_choices.at(i);