2015-09-17 25 views
0

我想表明连续4个辨认的按钮:项目有不正确的几何

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 
    } 
} 

然后第四个按钮被切断(好像额外的间距被引入或按钮太宽)。

如果我用而不是RowLayoutwidth而不是Layout.preferredWidth,项目显示正确。

他们为什么不与RowLayout

回答

1

RowLayout都有spacing属性。但是,如果你读了 spacing的文档,你可以看到,

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

RowLayoutspacing读取

这个属性保存每个单元之间的间距。 默认值是5

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