2016-07-01 43 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