Quantcast
Channel: Qt DevNet forums: Qt Quick 1283365070**
Viewing all articles
Browse latest Browse all 4972

how to access listview current item from other item?

$
0
0
hey, I modified your code a little look at this: //:D import QtQuick 2.0     Rectangle {     id: root;     height: 500;     width: 500;     Column     {         ListView         {             id: lv;             height: 400;             width: root.width;             clip: true;             orientation: ListView.Horizontal             snapMode: ListView.SnapOneItem;// added new :D                 model: ListModel{                 id: model;                 ListElement{ name :"1"; }                 ListElement{ name :"2"; }                 ListElement{ name :"3";}                 ListElement{ name :"4";}             }             delegate: com;         }         Text         {             id:txt;             height:100;             width:root.width;             text: lv.currentItem.name; // now you can use currentItem.name to access the property of the delegate         }     }     Component     {         id: com;         Rectangle         {             id: rec             property alias name: rectext.text // added this property alias to access the text of the current list item             height: 400;             width: root.width;             Text             {                 id: rectext;                 anchors.centerIn: parent;                 text: model.name;             }             MouseArea {                 anchors.fill: parent                 onClicked: {                     lv.currentIndex = index // you used listView.currentIndex here?                 }             }         }     }     } I’ve added a property to access the text and your MouseArea to the delegate, that works fine and you can use it, see my comments in the code. Might not be perfect because it only changes the index if you click on the item, not on you drag/swipe it, but that is another problem for now I think.. maybe you find a solution to that.

Viewing all articles
Browse latest Browse all 4972

Latest Images

Trending Articles



Latest Images