Select item in QML ListView and read data from it

3,367 views
Skip to first unread message

denonth

unread,
Feb 21, 2012, 3:01:42 PM2/21/12
to android-qt
Hi people,
So here is the problem.
I have made my app to get data from QT and show it in ListView in QML.
I want to make this listview mouseArea so on click I can select
certain item. Problem is that I have tried everything and still
nothing. And one more thing when I press selected item I want to show
values or use values in text_input1 for example. How to do that?
Here is my ListView code:

ListView {
id: listview1
x: 0
y: 82
// width: 574
// height: 967
width: window.width
height: window.height
visible: true
keyNavigationWraps: false
boundsBehavior: Flickable.DragAndOvershootBounds
opacity: 1
maximumFlickVelocity: 2500
anchors.leftMargin: 0
highlightMoveSpeed: 489
contentWidth: 0
preferredHighlightEnd: 2
spacing: 5
highlightRangeMode: ListView.NoHighlightRange
snapMode: ListView.SnapToItem
anchors.bottomMargin: 0
anchors.rightMargin: 0
anchors.topMargin: 82
anchors.fill: parent
model: myModel
delegate:Component {
// id: contactDelegate
Item {
property variant myData: model
width: 574; height: 90
Column {
Text { text: '<b>ID: </b> ' + id_korisnika ;
color:"steelblue"; font.family: "Helvetica"; font.pointSize: 10 }
Text { text: '<b>Ime: </b> ' +
ime_korisnika ; color:"steelblue"; font.family: "Helvetica";
font.pointSize: 10 }
Text { text: '<b>Prezime: </b> ' +
prezime_korisnika; color:"steelblue"; font.family: "Helvetica";
font.pointSize: 10 }
Text { text: '<b>Broj telefona: </b> ' +
broj_korisnika ; color:"steelblue"; font.family: "Helvetica";
font.pointSize: 10 }
Text { text: '<b>Adresa: </b> ' +
adresa_korisnika ; color:"steelblue"; font.family: "Helvetica";
font.pointSize: 10 }
}
}
}

// delegate: contactDelegate
highlight: Rectangle {color:"black"; radius: 5; opacity:
0.7 }
focus: true

}

Please help if you can.

Thank you

Enrico Miglino

unread,
Feb 21, 2012, 3:06:03 PM2/21/12
to andro...@googlegroups.com
Hi,

the delegate represents a generic element of the list, where you create the UI representation. There on the specific field of on all the item area you should create a mousearea and when you intercept the onClick event you can do what you need, e.g. launch another event (that is properly connected to the point where you should display the index. Try before in the onClick event to simply generate a console.log("...")  message including the list index.

cheers. Enrico

denonth

unread,
Feb 21, 2012, 3:09:31 PM2/21/12
to android-qt

I am sorry Enrico but I must say I don't understand you. So I need in
QT code make mousearea? Or?
Can you show me on my example what to do? If you need more code let me
know..

Thank you for helping me.


On Feb 21, 9:06 pm, Enrico Miglino <enrico.migl...@gmail.com> wrote:
> Hi,
>
> the delegate represents a generic element of the list, where you create the
> UI representation. There on the specific field of on all the item area you
> should create a mousearea and when you intercept the onClick event you can
> do what you need, e.g. launch another event (that is properly connected to
> the point where you should display the index. Try before in the onClick
> event to simply generate a console.log("...")  message including the list
> index.
>
> cheers. Enrico
>

Koying

unread,
Feb 21, 2012, 8:07:11 PM2/21/12
to andro...@googlegroups.com
denonth,

Sorry to reiterate, but those are basic QML questions better asked in the numerous Qt/QML forums around the net rather than this android specific group.
You seem quite far from understanding the basics of QML.

Just installing the Qt SDK for Win/Mac/Linux and checking the examples in there would be far more efficient (not speaking the doc with the numerous tutorials) than asking this limited group...

denonth

unread,
Feb 22, 2012, 12:07:35 PM2/22/12
to android-qt
Sorry for that,
I haven't understood him correctly. I have made it work. I have seen
examples.

I won't be posting anymore.

Ray Donnelly

unread,
Feb 22, 2012, 2:13:30 PM2/22/12
to andro...@googlegroups.com

We don't mind you posting but do expect questions to be directly related to our stuff and not general qt problems and we also ask that you do your homework!

Reply all
Reply to author
Forward
0 new messages