2016-06-15 89 views
1

我有一個qml佈局,並且ApplicationWindow不能伸展到正確的高度以滾動工作。QML佈局沒有正確的高度

這裏是我的代碼:

import QtQuick 2.4 
import QtQuick.Controls 1.3 
import QtQuick.LocalStorage 2.0 
import QtQuick.Window 2.0 
import "db.js" as DB 

ApplicationWindow { 
    id: root 
    visible: true 
    width: Screen.width 
    title: "Nákupy" 

    menuBar: MenuBar { 

     Menu { 
      title: "Smazat" 
      MenuItem { 
       text: "&Smazat seznam" 
       onTriggered: { 
        console.log("Open action triggered"); 
       } 
      } 
     } 
    } 

    Flickable { 
     id: flickable 
     anchors.fill: parent 
     contentHeight: column.height 
     contentWidth: root.width 

     Column { 
      anchors.fill: parent 
      id: column 

      Label { 
       id: welcometext 
       text: "Test" 
       horizontalAlignment: Text.AlignHCenter 
       y: 10 
       anchors.margins: 10 
       width: root.width 
      } 

      Repeater { 
       y: welcometext.top + welcometext.height + 10 
       id: repeater 
       model: lmodel 
       Button { 
        id: b 
        text: m_text 
        x: 20 
        width: root.width - 40 
        height: 70 
        onClicked: { 
         visible = false; 
        } 
       } 
      } 

      Button { 
       y: repeater.top + repeater.height + 30 
       width: root.width 
       text: "Přidat položku" 
       onClicked: { 
        console.log("clicked") 
       } 
      } 

     } 
    } 

    ListModel { 
     id: lmodel 
    } 

    Component.onCompleted: { 
     DB.open().transaction(function(tx){ 
      tx.executeSql("CREATE TABLE IF NOT EXISTS products (id INTEGER PRIMARY KEY, name TEXT, done INTEGER)"); 
     }); 
     console.log(column.height); 
     for(var i = 0; i < 10; i++) { 
      lmodel.append({m_text: "Test "+i}); 
     } 
     console.log(column.height); 
     console.log(welcometext.height); 
    } 

} 

列報告高度0

回答

0

嘗試使用implicitHeight

定義項目的自然寬度或高度,如果沒有寬度或高度指定。

對於大多數項的默認大小的隱式爲0x0,然而,一些物品具有不能被重寫的固有隱含尺寸[...]

設置隱含尺寸用於定義具有基於優選的大小是部件有用關於其內容[...]