2015-09-17 63 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