[Interest] QML Set data from a different model role
Nikita Krupenko
krnekit at gmail.com
Mon May 9 16:47:25 CEST 2016
2016-05-09 17:32 GMT+03:00 NoRulez <norulez at me.com>:
> I have a QStandardItemModel
>
> I also to overload the roleNames() function but then i get the error that "Role2" isn't defined.
>
>
>
>> Am 09.05.2016 um 15:50 schrieb Nikita Krupenko <krnekit at gmail.com>:
>>
>> 2016-05-09 9:19 GMT+03:00 NoRulez <norulez at me.com>:
>>> Hi,
>>>
>>> I want do show data in a combobox in QML and after a selection in the combo box is made I want the data but from a different role.
>>>
>>> In QML I have the following:
>>>
>>> ComboBox {
>>> model: MyModel
>>> textRole: "Role1"
>>> onCurrentTextChanged: {
>>> MyLineEdit.text = ?????? // Here I want the text from "Role2"
>>> }
>>> }
>>>
>>> MyLineEdit is a QML LineEdit
>>> The text for "Role1" works already.
>>> Could anybody please give me a help
>>>
>>> Thanks
>>> _______________________________________________
>>> Interest mailing list
>>> Interest at qt-project.org
>>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>> AFAIK, you have ho access to model data in ComboBox. But, you can get
>> it directly from model, like:
>>
>> MyLineEdit.text = MyModel.get(currentIndex)["Role2"]
>>
>> if you use ListModel, or some similar way if you have different model.
So, you need to use data() method. But you need to pass here
QModelIndex, which you could get only from DelegateModel, which not
used here :) I think, you can add to your model method, that return
data by an integer index and use it here.
More information about the Interest
mailing list