Note that there are some explanatory texts on larger screens.

plurals
  1. POQML ListView and ListModel index
    primarykey
    data
    text
    <p>I have a little problem with ListModel and ListView, in particular concerning the move function of ListModel. I will show you code snippets from the DynamicList example included in the SDK with some modifications just to debug it: Code:</p> <pre><code> Item { property alias nameText: nameTextBox.text id: delegateItem width: listView.width; height: 55 clip: true Row { anchors.verticalCenter: parent.verticalCenter spacing: 10 Column { Image { source: "content/pics/arrow-up.png" MouseArea { anchors.fill: parent; onClicked: { var voice var nameInModel var nameInView voice = listView.contentItem.children[1] nameInModel = fruitModel.get(1).name nameInView = voice.nameText console.log("name before move in model at 1: "+nameInModel) console.log("name before move in list at 1: "+nameInView) fruitModel.move(index, index-1, 1) voice = listView.contentItem.children[1] nameInView = voice.nameText nameInModel = fruitModel.get(1).name console.log("name after move in model at 1: "+nameInModel) console.log("name after move in list at 1: "+nameInView) } } } .... </code></pre> <p>So, when the image "content/pics/arrow-up.png" is clicked, one item in the model is moved up by one position, now, in the example there are four items in order: "Apple"-"Banana"-"Cumqat"-"Durian" and this is the result of consol.log if I click "up" on the "Banana" moving that item to the first position:</p> <p>name before move in model at 1: Banana name before move in list at 1: Apple name after move in model at 1: Apple name after move in list at 1: Apple</p> <p>This is what happens if I click on Apple (that now is in the 2nd place) to moving it to the 1st position:</p> <p>name before move in model at 1: Apple name before move in list at 1: Apple name after move in model at 1: Banana name after move in list at 1: Apple</p> <p>So, first of all it is evident that the first index of ListModel is 0 while the first index of ListView is 1, then it is evident that items in the model have been moved but items in the list have not. Now, this is my problem: Imagine that "name" is the text of a TextEdit, so the the ListView delegate includes a TextEdit and it can be edited by the user. If I want to take that text I know that I can do this: Code:</p> <pre><code>for (var i = 0; i &lt;= myListView.count; i++){ myItem= myListView.contentItem.children[i] myName = myListView.name </code></pre> <p>But here is the problem, in my ListView there is also the possibility to move the items by using the move function of ListModel but if I move items and I use the previous cycle to take the "name" nothing seems to change (exactly as in the DynamicList example). On the other hand, if I take the "name" by using:</p> <pre><code> myName= myListModel.get(i).name </code></pre> <p>then, nothing seems to change when I modify the text in the TextEdit and I try to take the "name",</p> <p>So, what I have to do to obtain a ListView with TextEdit and with the possibility to move itemsof which I can record any changment?</p> <p>I hope I have been clear, Thank you very much, Giammarco </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload