【问题标题】:Items created by Repeater have incorrect geometry中继器创建的项目具有不正确的几何形状
【发布时间】: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 代替RowLayoutwidth 代替Layout.preferredWidth,项目将正确显示。

他们为什么不用RowLayout

【问题讨论】:

    标签: qt layout qml qtquick2


    【解决方案1】:

    RowRowLayout 都具有 spacing 属性。但是,如果您阅读 Row spacing 的文档,您可以看到

    间距是相邻项目之间留空的像素数量。 默认间距为 0

    RowLayout spacing 读取

    此属性保存每个单元格之间的间距。 默认值为 5

    因此,基本上,将spacing: 0 添加到您的RowLayout

    【讨论】:

      猜你喜欢
      • 2015-06-18
      • 2021-09-23
      • 1970-01-01
      • 1970-01-01
      • 2012-11-15
      • 1970-01-01
      • 2012-11-10
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多