How can I align Item?



  • Hi, my code:

      Item {
        id: header
        anchors.top: parent.top
        Row {
          anchors.fill: parent
          Image {
            id: scoreText
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: header.left
            source: 'qrc:/images/score.png'
          }
          Text {
            id: score
            anchors.verticalCenter: parent.verticalCenter
            anchors.left: scoreText.right
            font.pointSize: 16
            font.bold: true
            color: '#ffffff'
            text: '11110'
          }
          Item { Layout.fillWidth:  true }
          Image {
            width: 32; height: 32
            source: 'qrc:/images/mainmenu.png'
            fillMode: Image.PreserveAspectFit
            MouseArea {
              onClicked: ;
            }
          }
        }
      }
    

    But I get this errors:
    .qml:14:7: QML Image: Cannot anchor to an item that isn't a parent or sibling.

    .qml:12:5: QML Row: Cannot specify left, right, horizontalCenter, fill or centerIn anchors for items inside Row. Row will not function.
    I want like this:
    alt text



  • I think that second error message is the telling one: if you're using a row to hold things in place, then you shouldn't use anchors on the left or right of objects that are in the row.

    If you need spaces around the items in the row, then you can set
    bottomPadding
    topPadding
    leftPadding
    rightPadding

    or just:

    padding


Log in to reply
 

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