我有一個 Grid,它的布局有 4 行 2 列,如下所示:
import QtQuick 2.9
import QtQuick.Controls 2.2
Item {
id: page
Grid {
property int buttonSize: height * 0.2
property int spacingSize: height * 0.04
id: grid
height: parent.height
spacing: spacingSize
anchors.horizontalCenter: parent.horizontalCenter
topPadding: spacingSize
flow: Grid.TopToBottom
columns: 2
rows: 4
Rectangle {
color: "blue"
height: grid.buttonSize
width: grid.buttonSize
visible: true //this comes from c , not always true
}
Rectangle {
color: "blue"
height: grid.buttonSize
width: grid.buttonSize
visible: true //this comes from c , not always true
}
Rectangle {
color: "blue"
height: grid.buttonSize
width: grid.buttonSize
visible: true //this comes from c , not always true
}
Rectangle {
color: "blue"
height: grid.buttonSize
width: grid.buttonSize
visible: true //this comes from c , not always true
}
Rectangle {
color: "blue"
height: grid.buttonSize
width: grid.buttonSize
visible: true //this comes from c , not always true
}
}
}
如果我有 5 個以上的可見元素(繪制了 2 列),則一切正常,但如果我有 4 個或更少的可見專案(繪制了 1 列),則網格保持列間距可見并且元素不居中。
我怎樣才能解決這個問題?謝謝
uj5u.com熱心網友回復:
解決方案很簡單,只需洗掉列數。這將使 Grid 僅在必要時創建列。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/496984.html