【发布时间】:2015-12-14 15:01:19
【问题描述】:
我想连续显示四个可勾选按钮:
import QtQuick 2.4
import QtQuick.Window 2.2
import QtQuick.Controls 1.2
import QtQuick.Layouts 1.1
Window {
id: main
visible: true
width: 600; height: 350
ColumnLayout {
id: mainColumn
anchors.fill: parent // takes all available width
RowLayout {
Repeater {
id: rep
model: ["first", "second", "third", "fourth"]
Component.onCompleted: console.log(count)
Button {
text: modelData
checkable: true
Layout.preferredWidth: mainColumn.width / rep.count // (!)
}
}
}
// more elements
}
}
然后第四个按钮被切断(好像引入了额外的间距或按钮太宽)。
如果我使用Row 代替RowLayout 和width 代替Layout.preferredWidth,项目将正确显示。
他们为什么不用RowLayout?
【问题讨论】: