Accessing item delegate by model index or why Quick sucks when working with models?
-
If I work with Itemdelgate I have proprty
model. but how to access propertymodelfrom a component in model with different index?
Do I have to write a function which returns model data on C++ side? -
@Kofr
modelproperties are accessible throughout the delegates.
Your question is quite confusing. Can you post an example of what you are trying to do ?@p3c0 I do not have a si,ple one example.
I have item delegate 1 item delegate 2.
I want to get data of item delegate 2 from inside item delegate 1. So I have to useQVariant QAbstractItemModel::data(const QModelIndex &index, int role = Qt::DisplayRole) constmanualy from qml.
And I get problem with updating data asrightCellInput: taskEditLayout.fullMdl.data(taskEditLayout.indx, DataModel.TaskNameRole)does not update binding when data is changed. -
@p3c0 I do not have a si,ple one example.
I have item delegate 1 item delegate 2.
I want to get data of item delegate 2 from inside item delegate 1. So I have to useQVariant QAbstractItemModel::data(const QModelIndex &index, int role = Qt::DisplayRole) constmanualy from qml.
And I get problem with updating data asrightCellInput: taskEditLayout.fullMdl.data(taskEditLayout.indx, DataModel.TaskNameRole)does not update binding when data is changed. -
@p3c0 I have
StackViewwith InitialItem withTreeViewwhich consist of delegates. On Click on delegate inTreeViewit pushes toStackViewJust another Component "edit window". In this "edit window" there is button to add child to current delegate item (we have tree model). Once I add a child I want the "edit window" of new child to be pushed to stack. But here as I do push from delegate 1 I am not able to passmodelproperty of new delegate. (stack.push(editWndw, {"mdl": taskEditLayout.mdl, "fullMdl": taskEditLayout.fullMdl, "indx": indx}) - here mdl is supposed to bemodelproperty of new delegate 2, but Iam not able to get this from delgate 1. -
@p3c0 I have
StackViewwith InitialItem withTreeViewwhich consist of delegates. On Click on delegate inTreeViewit pushes toStackViewJust another Component "edit window". In this "edit window" there is button to add child to current delegate item (we have tree model). Once I add a child I want the "edit window" of new child to be pushed to stack. But here as I do push from delegate 1 I am not able to passmodelproperty of new delegate. (stack.push(editWndw, {"mdl": taskEditLayout.mdl, "fullMdl": taskEditLayout.fullMdl, "indx": indx}) - here mdl is supposed to bemodelproperty of new delegate 2, but Iam not able to get this from delgate 1. -
@Kofr Well in that case instead of passing model object to different components, how about making it global property accessible from everywhere?
For eg.:
property QtObject myModel: treeview.model -
@p3c0 said:
treeview.model
You talk of full model when I need a property attached to delegates.
may be it is possible to change current delegate somehow. -
@Kofr Sorry but I'm unable to undertand the scenario. Is
modelyour own custom property inside delegate ?@p3c0 I am talking about this
ListView { id: view anchors.fill: parent model: RoleEntryModel {} focus: true delegate: ListDelegate { text: 'hsv(' + Number(model.hue).toFixed(2) + ',' + Number(model.saturation).toFixed() + ',' + Number(model.brightness).toFixed() + ')' color: model.name } highlight: ListHighlight { } }where hue, saturation, brightness are roles of the model.
-
@p3c0 I am talking about this
ListView { id: view anchors.fill: parent model: RoleEntryModel {} focus: true delegate: ListDelegate { text: 'hsv(' + Number(model.hue).toFixed(2) + ',' + Number(model.saturation).toFixed() + ',' + Number(model.brightness).toFixed() + ')' color: model.name } highlight: ListHighlight { } }where hue, saturation, brightness are roles of the model.
@Kofr So is it that you want to access the roles (namely hue, saturation, brightness) values from outside of this
ListViewdelegate ? If so then did you accessingListVIewmodel from outside ? Once you get hold of it the data can be accessed too. -
@Kofr So is it that you want to access the roles (namely hue, saturation, brightness) values from outside of this
ListViewdelegate ? If so then did you accessingListVIewmodel from outside ? Once you get hold of it the data can be accessed too.@p3c0 said:
@Kofr So is it that you want to access the roles (namely hue, saturation, brightness) values from outside of this ListView delegate ? If so then did you accessing ListVIew model from outside ? Once you get hold of it the data can be accessed too.
code above is just example, not my case. what I need is to get
model.roleNameof delegatejwhen I work in delegatei