2016-06-15 67 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,然而,一些物品具有不能被重写的固有隐含尺寸[...]

设置隐含尺寸用于定义具有基于优选的大小是部件有用关于其内容[...]