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. Help with alignment of Row{} items.
Forum Update on Monday, May 27th 2025

Help with alignment of Row{} items.

Scheduled Pinned Locked Moved Solved QML and Qt Quick
2 Posts 2 Posters 444 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.
  • C Offline
    C Offline
    Circuits
    wrote on last edited by
    #1

    I am having trouble figuring out how to align items that are in a row. For instance, here is a simple example with some code:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        
        Row
        {
            id: _theRow
            spacing: 5
    
            Rectangle
            {
                id: _theRectangle
                width: 50
                height: 50
                color: "red"
            }
    
            Text
            {
                id: _theTextOne
                text: "value"
            }
        }
    
        Text
         {
            id: _theTextTwo
            text: "unit"
         }
    }
    

    What I want to be able to do is center _theTextOne inside the _theRectangle. However, if I try to use anchors I get errors about using them within Row. If try not using Row then I have trouble with spacing _theRectangle and _theTextTwo, any suggestions?

    1 Reply Last reply
    0
    • MarkkyboyM Offline
      MarkkyboyM Offline
      Markkyboy
      wrote on last edited by Markkyboy
      #2

      You need to nest _theTextOne inside _theRectangle, then you can use anchors, as follows;

      import QtQuick 2.12
      import QtQuick.Window 2.12
      
      Window {
          visible: true
          width: 640
          height: 480
          title: qsTr("Hello World")
      
          Row {
              id: _theRow
              spacing: 5
      
              Rectangle {
                  id: _theRectangle
                  width: 50
                  height: 50
                  color: "red"
      
                  Text {
                      id: _theTextOne
                       text: "value"
                       anchors.centerIn: parent
                  }
              }
          }
          Text {
              id: _theTextTwo
              text: "unit"
          }
      }
      

      Don't just sit there standing around, pick up a shovel and sweep up!

      I live by the sea, not in it.

      1 Reply Last reply
      2

      • Login

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