Simple QML visual string list need.



  • 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


  • Lifetime Qt Champion

    Hi,

    Do you mean something like described here ?



  • 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.



  • @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 you

    LA
    import QtQuick 2.6
    import QtQuick.Window 2.2
    import QtQuick.Controls 2.0

    Window {
    visible: true
    width: 640
    height: 480

    ListView {
        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"
            }
    }
    

    }



  • 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?


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.