Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Regarding lisview again
Qt 6.11 is out! See what's new in the release blog

Regarding lisview again

Scheduled Pinned Locked Moved QML and Qt Quick
5 Posts 2 Posters 2.3k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Pradeep KumarP Offline
    Pradeep KumarP Offline
    Pradeep Kumar
    wrote on last edited by p3c0
    #1

    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.

    Pradeep Kumar
    Qt,QML Developer

    p3c0P 1 Reply Last reply
    0
    • Pradeep KumarP Pradeep Kumar

      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.

      p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by p3c0
      #2

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

      157

      Pradeep KumarP 2 Replies Last reply
      0
      • p3c0P p3c0

        @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.
        Pradeep KumarP Offline
        Pradeep KumarP Offline
        Pradeep Kumar
        wrote on last edited by
        #3

        @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

        Pradeep Kumar
        Qt,QML Developer

        1 Reply Last reply
        0
        • p3c0P p3c0

          @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.
          Pradeep KumarP Offline
          Pradeep KumarP Offline
          Pradeep Kumar
          wrote on last edited by
          #4

          @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

          Pradeep Kumar
          Qt,QML Developer

          p3c0P 1 Reply Last reply
          0
          • Pradeep KumarP Pradeep Kumar

            @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

            p3c0P Offline
            p3c0P Offline
            p3c0
            Moderators
            wrote on last edited by
            #5

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

            157

            1 Reply Last reply
            1

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved