代码之家  ›  专栏  ›  技术社区  ›  marmistrz

Repeater创建的项目具有不正确的几何结构

  •  0
  • marmistrz  · 技术社区  · 10 年前

    我想连续显示四个可检查按钮:

    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 ,项目将正确显示。

    为什么他们没有 行列式 ?

    1 回复  |  直到 10 年前
        1
  •  1
  •   BaCaRoZzo Indie Dev    10 年前

    二者都 Row RowLayout 拥有 spacing 所有物但是,如果您阅读文档 一行 spacing 你可以看到

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

    行列式 spacing 读取

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

    所以,基本上,补充道 spacing: 0 到您的 行列式 .