ItemSelector is hard to use with generic models

Bug #1242531 reported by Alberto Mardegan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Ubuntu UI Toolkit
Triaged
Low
Unassigned
ubuntu-ui-toolkit (Ubuntu)
Triaged
Low
Unassigned

Bug Description

Hi!
  The default delegate of ItemSelector, OptionSelectorDelegate, expects the text to be displayed to be in the "modelData" context variable. However, this variable is normally only available for ListModel or QStringList models. It's not clear how one should use ItemSelector with another model (defined from C++, for instance) which defines other role names but not "modelData".

I tried replacing the delegate of ItemSelector with a custom delegate, but nothing was displayed. I guess some documentation needs to be added to explain how to replace the delegate.

I ended up with this solution, which seems to be working well:

===============
        ListItem.ItemSelector {
            anchors.left: parent.left
            anchors.right: parent.right
            text: "Account"
            model: root.model
            delegate: OptionSelectorDelegate {
                property string modelData: model.displayName
            }
        }
===============

However, I wonder if this will be supported in the future or if I run the risk of seeing my code break when a new version of the UI toolkit is released.
So, I'd recommend to add documentation on how to address this case; also, the OptionSelectorDelegate is currently not displayed in the documentation, but I think it should be.

Revision history for this message
Zsombor Egri (zsombi) wrote :

modelData is available also in Repeater, generally available when the model is a number, an array or contains objects with one single role.

Changed in ubuntu-ui-toolkit:
status: New → Triaged
importance: Undecided → Low
Zoltan Balogh (bzoltan)
Changed in ubuntu-ui-toolkit (Ubuntu):
importance: Undecided → Low
status: New → Triaged
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.