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. Table of elements using ColumnLayout and RowLayout
Forum Updated to NodeBB v4.3 + New Features

Table of elements using ColumnLayout and RowLayout

Scheduled Pinned Locked Moved Solved QML and Qt Quick
tablerowlayoutcolumnlayoutalignment
4 Posts 2 Posters 1.1k Views
  • 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.
  • K Offline
    K Offline
    Kyeiv
    wrote on 20 Jul 2021, 06:58 last edited by
    #1

    I want to achieve something like:

    ____________________________________
    |   some        text2       texrrr  |
     ___________________________________
    |  another    another222  another33 |
     ___________________________________
    |   txt1        txt22      text333  |
     ___________________________________
    | longtext    longtext   tooolong...|
    ____________________________________
    

    So table of Text aligned like in the example and with each row separated.

    And i dont know what to do when text is too big and interferes with another one

    I tried various combinations but every had some problems with this formatting, for example:

    ColumnLayout {
        anchors.fill: parent
        RowLayout{
            Layout.fillWidth: true
            Item
            {
                Layout.fillWidth: true
                height: bodyLabel.height
    
                Text
                {
                    id: bodyLabel
                    anchors.left: parent.left
                    text: "another"
                    color: "white"
                }
                Text
                {
                    anchors.horizontalCenter : parent.horizontalCenter
                    text: "another33"
                    color: "white"
                }
                Text
                {
                    anchors.right: parent.right
                    text: "another222"
                    color: "white"
                }
            }
        }
        Item
        {
            Layout.fillWidth: true
            height: 10
            Rectangle
            {
                height: 1
                width: parent.width
                anchors.centerIn: parent
                color: "grey"
            }
        }
    }
    

    and:

    ColumnLayout {
        anchors.fill: parent
        RowLayout{
            Layout.fillWidth: true
    
            Text
            {
                Layout.fillWidth: true
                text: "another"
                color: "white"
            }
            Text
            {
                Layout.fillWidth: true
                text: "another33"
                color: "white"
            }
            Text
            {
                Layout.fillWidth: true
                text: "another222"
                color: "white"
            }
        }
        Item
        {
            Layout.fillWidth: true
            height: 10
            Rectangle
            {
                height: 1
                width: parent.width
                anchors.centerIn: parent
                color: "grey"
            }
        }
    }
    
    1 Reply Last reply
    0
    • N Offline
      N Offline
      ndias
      wrote on 20 Jul 2021, 09:30 last edited by ndias
      #2

      Hi @Kyeiv ,

      Please find solution bellow. You should use elide: Text.ElideRight to wrap text labels.

      import QtQuick
      import QtQuick.Window
      import QtQuick.Controls
      import QtQuick.Layouts
      
      Window {
      
          ColumnLayout {
              anchors.fill: parent
      
              RowLayout{
                  Text {
                      Layout.fillWidth: true
                      text: "Text1a"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text1b"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text1c"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
              }
      
              Item {
                  Layout.fillWidth: true
                  height: 10
                  Rectangle
                  {
                      height: 1
                      width: parent.width
                      anchors.centerIn: parent
                      color: "grey"
                  }
              }
      
              RowLayout{
                  Text {
                      Layout.fillWidth: true
                      text: "Text2a"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text2b"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text2c"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
              }
      
              Item {
                  Layout.fillWidth: true
                  height: 10
                  Rectangle
                  {
                      height: 1
                      width: parent.width
                      anchors.centerIn: parent
                      color: "grey"
                  }
              }
      
              RowLayout{
                  Text {
                      Layout.fillWidth: true
                      text: "Text3a"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text3b"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text3c"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
              }
      
          }
      
      }
      

      d2c8b52e-53d4-4463-a747-46c00b0c542b-image.png

      Best Regards

      K 1 Reply Last reply 20 Jul 2021, 11:36
      0
      • N ndias
        20 Jul 2021, 09:30

        Hi @Kyeiv ,

        Please find solution bellow. You should use elide: Text.ElideRight to wrap text labels.

        import QtQuick
        import QtQuick.Window
        import QtQuick.Controls
        import QtQuick.Layouts
        
        Window {
        
            ColumnLayout {
                anchors.fill: parent
        
                RowLayout{
                    Text {
                        Layout.fillWidth: true
                        text: "Text1a"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                    Text {
                        Layout.fillWidth: true
                        text: "Text1b"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                    Text {
                        Layout.fillWidth: true
                        text: "Text1c"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                }
        
                Item {
                    Layout.fillWidth: true
                    height: 10
                    Rectangle
                    {
                        height: 1
                        width: parent.width
                        anchors.centerIn: parent
                        color: "grey"
                    }
                }
        
                RowLayout{
                    Text {
                        Layout.fillWidth: true
                        text: "Text2a"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                    Text {
                        Layout.fillWidth: true
                        text: "Text2b"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                    Text {
                        Layout.fillWidth: true
                        text: "Text2c"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                }
        
                Item {
                    Layout.fillWidth: true
                    height: 10
                    Rectangle
                    {
                        height: 1
                        width: parent.width
                        anchors.centerIn: parent
                        color: "grey"
                    }
                }
        
                RowLayout{
                    Text {
                        Layout.fillWidth: true
                        text: "Text3a"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                    Text {
                        Layout.fillWidth: true
                        text: "Text3b"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                    Text {
                        Layout.fillWidth: true
                        text: "Text3c"
                        horizontalAlignment : Text.AlignHCenter
                        elide: Text.ElideRight
                    }
                }
        
            }
        
        }
        

        d2c8b52e-53d4-4463-a747-46c00b0c542b-image.png

        Best Regards

        K Offline
        K Offline
        Kyeiv
        wrote on 20 Jul 2021, 11:36 last edited by
        #3

        @ndias
        Screenshot from 2021-07-20 13-34-34.png

        this happens when applying your solution

        N 1 Reply Last reply 20 Jul 2021, 11:57
        0
        • K Kyeiv
          20 Jul 2021, 11:36

          @ndias
          Screenshot from 2021-07-20 13-34-34.png

          this happens when applying your solution

          N Offline
          N Offline
          ndias
          wrote on 20 Jul 2021, 11:57 last edited by ndias
          #4

          Hi @Kyeiv ,
          I didn't realize that you wanted the elements of each line to line up with each other. In this case you can use GridLayout:

          
          import QtQuick
          import QtQuick.Window
          import QtQuick.Controls
          import QtQuick.Layouts
          
          Window {
          
              GridLayout {
                  anchors.fill: parent
          
                  columns: 3
                  //rows: 5
          
          
                  Text {
                      Layout.fillWidth: true
                      text: "Text1a Looooooooog"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text1b"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text1c"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
          
          
                  Item {
                      Layout.columnSpan: 3
                      Layout.fillWidth: true
                      height: 10
                      Rectangle
                      {
                          height: 1
                          width: parent.width
                          anchors.centerIn: parent
                          color: "grey"
                      }
                  }
          
          
                  Text {
                      Layout.fillWidth: true
                      text: "Text2a"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text2b Looooooooog"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text2c"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
          ´
          
                  Item {
                      Layout.columnSpan: 3
                      Layout.fillWidth: true
                      height: 10
                      Rectangle
                      {
                          height: 1
                          width: parent.width
                          anchors.centerIn: parent
                          color: "grey"
                      }
                  }
          
          
                  Text {
                      Layout.fillWidth: true
                      text: "Text3a"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text3b"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
                  Text {
                      Layout.fillWidth: true
                      text: "Text3c Looooooooog"
                      horizontalAlignment : Text.AlignHCenter
                      elide: Text.ElideRight
                  }
          
              }
          }
          

          80bb60b9-e0d8-4200-9aff-b91995e3daf7-image.png
          da6d1565-5132-45f8-bd56-95be08ea8f2f-image.png

          1 Reply Last reply
          1

          1/4

          20 Jul 2021, 06:58

          • Login

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