2016-07-01 42 views
1

我在我的应用程序中添加了一个简单的TextArea。不幸的是,即使其contentHeight绕过其height,我也无法滚动文本。
下面是代码:QML TextArea不会滚动

import QtQuick 2.7 
import QtQuick.Controls 2.0 

ApplicationWindow { 
    id: appWindow 
    visible: true 
    width: 480 
    height: 640 
    TextArea{ 
     anchors.fill: parent 
     anchors.margins: 100 
     wrapMode: TextEdit.Wrap 
     Component.onCompleted: { 
      console.log("width:", width) 
      console.log("contentWidth:", contentWidth) 
      console.log("height:", height) 
      console.log("contentHeight:", contentHeight) 
     } 
     onTextChanged: { 
      console.log("width:", width) 
      console.log("contentWidth:", contentWidth) 
      console.log("height:", height) 
      console.log("contentHeight:", contentHeight) 
     } 
    } 
} 

回答

3

TextArea是不是默认滚动的,主要是为了使有可能具有多行编辑当作滚动页面的一部分,而不必嵌套Flickable s,这常常赋予次优经验。为了使独立的TextArea可滚动,您可以将其附加到Flickable,如documentation中所示。

+0

我最初想用一个Label从我的服务器获取预定义的文本。即使使用Flickable,我也无法滚动浏览标签:/ –

+0

您可以在“Flickable”中包含“Label”代码,我可以在答案中滚动浏览代码吗? –

+0

将'Flickable :: contentHeight'绑定到标签的高度。 – jpnurmi