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. Sibling anchors don't align properly
Qt 6.11 is out! See what's new in the release blog

Sibling anchors don't align properly

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 2.1k 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.
  • R Offline
    R Offline
    richterX
    wrote on last edited by
    #1

    Hello,
    I am just learning Qt Quick. I have a lot of experience developing Windows applications and some experience with web development and javascript (but its been a few months). I am trying to achieve this:
    !http://dl.dropbox.com/u/47808160/whatIwant.PNG(whatIwant)!

    But instead I get:
    !http://dl.dropbox.com/u/47808160/whatIget.PNG(What I get)!

    Here is my main code:
    @Rectangle {
    width: 800
    height: 600
    color: "#0E113D"

    BatteryIndicator {
        id: batteryIndicator
        anchors.left: parent.left
        anchors.top: parent.top
        anchors.leftMargin: 10
        anchors.topMargin: 10
        borderColor: "#00A14B"
        fillColor: "#69BD45"
        fontColor: "#00A14B"
        percentage: 75
        statusMsg: "01:32"
    }
    
    SubsysIndicator {
        id: indicator1
        anchors.top: batteryIndicator.bottom
        anchors.topMargin: 30
        anchors.left: parent.left
        anchors.leftMargin: 10
        name: "ID1"
    }
    
    SubsysIndicator {
        id: indicator2
        anchors.verticalCenter: indicator1.verticalCenter
        anchors.left: indicator1.right
        anchors.leftMargin: 10
        name: "ID2"
    }
    
    SubsysIndicator {
        id: indicator3
        anchors.verticalCenter: indicator1.verticalCenter
        anchors.left: indicator2.right
        anchors.leftMargin: 10
        name: "ID3"
    }
    
    SubsysIndicator {
        id: indicator4
        anchors.verticalCenter: indicator1.verticalCenter
        anchors.left: indicator3.right
        anchors.leftMargin: 10
        name: "ID4"
    }
    

    }@

    And here is my code for SubsysIndicator:

    @Rectangle {
    property string name: "sys#"
    property string imageSource: ""

    Text{
        id: label
        text: name
        color: "white"
        font.pixelSize: 18
        font.family: "Myriad Pro"
    }
    
    Image{
        id: icon
        source: "images/status-black.png"
        anchors.left: label.right
        anchors.leftMargin: 5
        anchors.verticalCenter: label.verticalCenter
    }
    

    }@

    Thanks for the help!

    1 Reply Last reply
    0
    • M Offline
      M Offline
      mbrasser
      wrote on last edited by
      #2

      Hi,

      The issue is that the SubsysIndicator doesn't provide a size (and by default a Rectangle has a size of 0,0). If you want the size to be based on the Text/Image size, you could add:

      @
      width: childrenRect.width
      height: childrenRect.height
      @

      to the Rectangle in SubsysIndicator.qml.

      Regards,
      Michael

      1 Reply Last reply
      0
      • R Offline
        R Offline
        richterX
        wrote on last edited by
        #3

        Thank you, that resolved my problem.

        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