Regarding lisview again



  • I have a sample code,
    listviewmodel.qml

    import QtQuick 2.0
    
    ListModel {
        ListElement {
            name: "Applcccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccccjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjccccccccccccccccccccccccccce"
            cost: "30"
        }
        ListElement {
            name: "Mango"
            cost: "50"
        }
        ListElement {
            name: "Papaya"
            cost: "40"
        }
        ListElement {
            name: "Orange"
            cost: "30"
        }
    }
    

    main.qml

    import QtQuick 2.3
    import QtQuick.Window 2.2
    import QtQuick.Layouts 1.1
    import QtQuick.Controls 1.2
    
    Window
    {
        width: 400
        height: 200
        visible: true
        ListView {
            id: ls
            width: 400; height: 200
            property int maxLen : 0
    
            model: ListViewModel {
                   id : myModel
                 Component.onCompleted: {
                     console.log("Model loaded")
                     for(var i=0;i<myModel.count;i++)
                     {
                         var obj = myModel.get(i);
                      //   var inObj = obj.get(i);
                         console.log("i=",obj.name)
                     }
                 }
            }
            delegate:
                Row{
                Rectangle
                {
                    id: rect
                    width: ls.width/2
                    height: ls.height/5
    
                    Text {
                        id: t1
                        width: ls.width/2
                        height: 50
                        text: name
                        wrapMode: Text.Wrap
    //                    elide: Text.ElideMiddle
                        //Action.tooltip: "Pradeep"
                    }
                }
                Rectangle
                {
                    id: rect1
                    width: ls.width/2
                    height: ls.height/5
                    Text {
                        id: t2
                        width: rect1.width/2
                        height: 50
                        text: cost
                        anchors.right: rect1.right
                    }
                }
            }
        }
    }
    

    i have found the role string printing in console,
    but i want to find the length, how?.

    and with respect to length, align the rolenames of name accordingingly,after finding the maximum,align the rest name rolenames accordingly w.r.t to maximum, if cost increases w.r.t to cost rolenames, i want to align respectively
    finding the cost rolenames of maximum, then aign the others.


  • Moderators

    @Pradeep-Kumar.M

    i have found the role string printing in console,
    but i want to find the length, how?.

    As said in your last post, use length to get the length.

    console.log("i=",obj.name.length)
    

    and with respect to length, align the rolenames of name accordingingly,after finding the maximum,align the rest name rolenames accordingly w.r.t to maximum, if cost increases w.r.t to cost rolenames, i want to align respectively
    finding the cost rolenames of maximum, then aign the others.

    What do you meaning by aligning here ? Where do you want to align.


    Also please note few important things to keep this forum healthy:

    • Always format you code neatly, keep it minimal and surrounding code with ``` (3 backticks) while posting it here so that it looks nice and easier to read.
    • Marking the post as solved if done.
    • Upvoting the answers that you found useful which in turn helps others that it worked.


  • @p3c0

    k k. i keep the code minimal and with respect to code to be neat while posting.

    for ex:

    output: applefgggggggggggg : 50
    aaaaaaaaaaa: 40
    nhfgfg: 30

    i require:

                    applefgggggggggggg  :      50
                   aaaaaaaaaaa                :      40
                   nhfgfg                           :      30
    

    w.r.t first align in order w.r.t to first length



  • @p3c0

    k k. i keep the code minimal and with respect to code to be neat while posting.

    for ex:

    output: applefgggggggggggg : 50
    aaaaaaaaaaa: 40
    nhfgfg: 30

    i require:

                applefgggggggggggg  :      50
                aaaaaaaaaaa         :      40
                nhfgfg              :      30
    

    w.r.t first align in order w.r.t to first length


  • Moderators

    @Pradeep-Kumar.M For this you need to do sorting. There's no ready-made function for it. You will need to implement your own.
    Check this.


Log in to reply
 

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