我的代码:
import QtQuick 2.6
import QtQuick.Window 2.2
import QtQuick.Layouts 1.3
Window {
visible: true
width: 640
height: 480
GridLayout {
id: grid
anchors.fill: parent
columns: 6
Repeater {
model: 7
Rectangle {
color: "blue"
Layout.fillWidth: true
Layout.fillHeight: true
}
}
//Rectangle {color: "red"; width: 20; height: 20}
}
}
它显示了这个:
哪个好 .
但是当您取消注释包含 color: "red"
的行时,布局会中断:
知道为什么会这样,以及如何解决它?
1 回答
我'm not sure if it'导致您的问题,因为我没有测试过,但您should avoid设置
width
和height
由Layout
管理的项目:例如,您应该使用
Layout.preferredWidth
而不是width
.有关更多信息,请参阅Specifying Preferred Size .