Simple QML visual string list need.
-
wrote on 22 Nov 2017, 09:53 last edited by
I tried but it is not showing any selection. even a text bolding is enough.
If you can point a standard sample will be good. now i am refering stringlistmodel of Qt 5.9 -
Hi,
Do you mean something like described here ?
-
wrote on 23 Nov 2017, 08:34 last edited by
not exactly. Basically I want a list in traditional way where you can see a selected item.
I think I have done it with this modification. May be it is a workaround. please see this here.
== code when I dont have selection indication ==import QtQuick 2.0 ListView { width: 100; height: 100 model: myModel delegate: Rectangle { height: 25 width: 100 Text { text: modelData } } }
== code now; now I can see clicktime selection ==
import QtQuick 2.0 import QtQuick.Controls 2.2 ListView { width: 100; height: 100 model: myModel delegate: ItemDelegate { height: 25 width: parent.width Text { text: modelData } } }
I am not sure whether ItemDelegate is the right way to solve this. Please advise if there is another method. still it is only showing selection at the time of click. it is not persisting as I have selected that item in the list.
-
wrote on 23 Nov 2017, 23:43 last edited by
@veenusav hello,
do you want to select multiple items in your list ?This is an exemple with only one selectable item,but you can easily modify it to be able to select multiple items
I hope it will help youLA
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Controls 2.0Window {
visible: true
width: 640
height: 480ListView { id:list width: 100; height: 100 property int _ind:1 model: myModel currentIndex: _ind delegate: Rectangle { id:item height: 25 color: ListView.isCurrentItem ? "black" : "red" width: parent.width Text{ color: item.ListView.isCurrentItem ? "red" : "black" text: name } MouseArea{ anchors.fill: parent onClicked: { list._ind = index } } } } ListModel{ id:myModel ListElement{ name : "Item1" } ListElement{ name : "Item2" } ListElement{ name : "Item3" } ListElement{ name : "Item4" } }
}
-
wrote on 24 Nov 2017, 04:10 last edited by
Have you seen the highlight examples in the Qt Creator example project "Qt Quick Examples - Views"?
http://doc.qt.io/qt-5/qtquick-views-example.html
It may put you on track?
1/5