2016-11-07 68 views
0

我有被設計來顯示的圖像與一些文本下它如下一個簡單的組件:QML不居中部件

Rectangle{ 
    id: functionView 

    RowLayout { 
     spacing: 350 
     anchors.centerIn: parent 

     Item { 
      Image { 
       id: upload_pic 
       source: "http://icons.iconarchive.com/icons/custom-icon-design/mono-general-4/128/upload-icon.png" 
       Text { 
        text: "Upload Images" 
        anchors.bottom: parent.bottom 
        anchors.horizontalCenter: parent.horizontalCenter 
        anchors.bottomMargin: -20 
       } 
      } 
      Layout.fillWidth: true 
     } 

     Item { 
      Image { 
       id: workflow_pic 
       source: "http://icons.iconarchive.com/icons/icons8/windows-8/128/Data-Workflow-icon.png" 
       Text { 
        text: "Upload Workflow" 
        anchors.bottom: parent.bottom 
        anchors.horizontalCenter: parent.horizontalCenter 
        anchors.bottomMargin: -20 
       } 
      } 
      Layout.fillWidth: true 
     } 


    } 
} 

然而,這是不對齊的(水平或垂直)組件窗口。這可以使用qmlscene進行驗證。圖像直接鏈接到組件源中。

回答

0

您正試圖將您的RowLayout置於其父母中,這是一個Rectangle,它沒有其width屬性集。 矩形的寬度設置爲某個值或通過width: parent.width例如其父寬度或通過設置錨一樣,例如:

anchors.left: parent.left 
anchors.right: parent.right 
+0

此,不幸的是,沒有爲我工作。 – Luca

+0

您需要爲高度做同樣的事情。設置矩形的'anchors.fill:parent' – derM