Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. What is the proper way to create layout in qml

What is the proper way to create layout in qml

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 3 Posters 626 Views 1 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.
  • AhtiA Offline
    AhtiA Offline
    Ahti
    wrote on last edited by
    #1

    Hi
    I am trying to create a layout for controls but I am not getting how to do it. I want to it to look similar to this:

    0_1560318042933_qml layout.PNG

    please help

    what is a signature ?? Lol

    jsulmJ 1 Reply Last reply
    0
    • AhtiA Ahti

      Hi
      I am trying to create a layout for controls but I am not getting how to do it. I want to it to look similar to this:

      0_1560318042933_qml layout.PNG

      please help

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @Ahti Looks like https://doc.qt.io/qt-5/qml-qtquick-layouts-gridlayout.html
      Also take a look at https://doc.qt.io/qt-5/qtquicklayouts-index.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      2
      • Shrinidhi UpadhyayaS Offline
        Shrinidhi UpadhyayaS Offline
        Shrinidhi Upadhyaya
        wrote on last edited by Shrinidhi Upadhyaya
        #3

        Hi @Ahti , if the components are similar and repeating i guess you can use Repeater.

        Here is a sample code:-

        RowLayout {
            anchors.fill: parent
            spacing: 20
        
            ColumnLayout {
                Layout.preferredHeight: parent.height
                Layout.preferredWidth: parent.width
        
                Repeater {
                    model: 4
        
                    TextField {
                        Layout.preferredWidth: 200
                        Layout.preferredHeight: 40
                        placeholderText: qsTr("Text ") + index
                        Layout.alignment: Qt.AlignRight
                    }
                }
            }
        
            ColumnLayout {
                Layout.preferredHeight: parent.height
                Layout.preferredWidth: parent.width
        
                Repeater {
                    model: 4
                    
                    Button {
                        Layout.preferredWidth: 200
                        Layout.preferredHeight: 40
                        text: "Control " + index
                    }
                }
            }
        }
        

        Sample Output:-

        0_1560321655987_773c1b67-15d3-4e81-82bf-771ec4db45e4-image.png

        For more information:-

        Repeater[https://doc.qt.io/qt-5/qml-qtquick-repeater.html]
        Layouts[https://doc.qt.io/qt-5/qtquicklayouts-index.html]

        Shrinidhi Upadhyaya.
        Upvote the answer(s) that helped you to solve the issue.

        AhtiA 1 Reply Last reply
        4
        • Shrinidhi UpadhyayaS Shrinidhi Upadhyaya

          Hi @Ahti , if the components are similar and repeating i guess you can use Repeater.

          Here is a sample code:-

          RowLayout {
              anchors.fill: parent
              spacing: 20
          
              ColumnLayout {
                  Layout.preferredHeight: parent.height
                  Layout.preferredWidth: parent.width
          
                  Repeater {
                      model: 4
          
                      TextField {
                          Layout.preferredWidth: 200
                          Layout.preferredHeight: 40
                          placeholderText: qsTr("Text ") + index
                          Layout.alignment: Qt.AlignRight
                      }
                  }
              }
          
              ColumnLayout {
                  Layout.preferredHeight: parent.height
                  Layout.preferredWidth: parent.width
          
                  Repeater {
                      model: 4
                      
                      Button {
                          Layout.preferredWidth: 200
                          Layout.preferredHeight: 40
                          text: "Control " + index
                      }
                  }
              }
          }
          

          Sample Output:-

          0_1560321655987_773c1b67-15d3-4e81-82bf-771ec4db45e4-image.png

          For more information:-

          Repeater[https://doc.qt.io/qt-5/qml-qtquick-repeater.html]
          Layouts[https://doc.qt.io/qt-5/qtquicklayouts-index.html]

          AhtiA Offline
          AhtiA Offline
          Ahti
          wrote on last edited by Ahti
          #4

          @Shrinidhi-Upadhyaya well now I want some text to have multiple controls in one group and others with one. Can I do that with your solution ?

          what is a signature ?? Lol

          1 Reply Last reply
          0

          • Login

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