2017-01-30 31 views
1

我想了解爲什麼在使用qmlscene進行顯示時,此示例沒有繪製任何Rectangle?是否可以合併和Column組件以創建網格?瞭解行和列布局

import QtQuick 2.7 
import QtQuick.Controls 1.4 
import QtQuick.Controls 2.1 
import QtQuick.Controls.Material 2.0 
import QtQuick.Dialogs 1.2 
import QtQuick.Layouts 1.3 

Pane { 
    anchors.fill: parent 
    Row { 
     anchors.fill: parent 
     Column { 
      anchors.top: parent.top 
      anchors.bottom: parent.bottom 
      Rectangle {border.color: "red";color: "blue"; anchors.left: parent.left;anchors.right: parent.right; height: parent.height;width: parent.width} 
     } 
     Column { 
      anchors.top: parent.top 
      anchors.bottom: parent.bottom 
      Rectangle {border.color: "red";color: "green";anchors.left: parent.left;anchors.right: parent.right; height: parent.height; width: parent.width} 
     } 
    } 
} 

經過Qt 5.8的測試,我得到了一個空的白色屏幕。

回答

2

您看起來像是將Rectanglewidth設置爲其各自父公司Columnwidth。但這些沒有任何width輪流設置。

嘗試設置widthColumn的S-如下:

width: parent.width/2 

這應該行分成兩個Column秒。我假設這是你正在尋找的行爲,如果不是,你可以嘗試QML Grid控制來獲得更好的紋理控制佈局。

+0

關於「行」和「列」組件的關鍵點是它們不計算寬度或高度,它們只是按照連續順序放置項目。那是我的錯誤。 – Nulik