[Qt-qml] Listview contentheight woes

martin.jones at nokia.com martin.jones at nokia.com
Mon Feb 14 03:52:46 CET 2011


Hi Amit,

The problem is that you are anchoring the delegate to the size of its parent, rather than allowing its height to be calculated based on the delegate's contents.  Setting only the width of the delegate fixes the example.

--- MultiLineText.qml.orig      2011-02-14 12:49:44.996256232 +1000
+++ MultiLineText.qml   2011-02-14 12:49:49.324245470 +1000
@@ -18,7 +18,7 @@
         Text{
             id:scrollText

-            anchors.fill: parent;
+            width: parent.width
             wrapMode:Text.WordWrap;
             font.family: mlt_fontfamily;
             font.pixelSize:0

Br,
Martin.

From: qt-qml-bounces+martin.jones=nokia.com at qt.nokia.com [mailto:qt-qml-bounces+martin.jones=nokia.com at qt.nokia.com] On Behalf Of ext amit shah
Sent: Saturday, 12 February 2011 1:32 PM
To: qt-qml at qt.nokia.com
Subject: [Qt-qml] Listview contentheight woes

Hi,
 I'am in a process of building a multi-line text viewer with scroll bars.
I have implemented  my component MultiLineText in a separate file .

The MultiLine component has a ListView and I'm using contentHeight property of ListView drive the logic for  scrolling. I have not attached the scrolling component code.

The problem is the contentHeight value is displaying as 200 which is the height of the listview.

Here is the code, the driver code is implemented in focusKey.qml .

Any ideas as why contentHeight is not being calculated correctly.


thanks
--amit

File:focusKey.qml
=================
FocusScope {
    width: 1280
    height: 480
    focus: true
          Rectangle{
                color: "#d32828"

                border.color: "black"
                anchors.fill: parent;
                smooth:true
              MultiLineText{

                     id:test
                          width: 300;height: 200;
                     anchors{top:parent.top;topMargin:100;left:parent.left;leftMargin:500}
                     opacity: 0.5

                     mlt_dataText:"
            1Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32
                        2Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32
                        3Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32
                        4ontrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32
                        5Contrary to popular belief, Lorem Ipsum is not simply random text. It has roots in a piece of classical Latin literature from 45 BC, making it over 2000 years old. Richard McClintock, a Latin professor at Hampden-Sydney College in Virginia, looked up one of the more obscure Latin words, consectetur, from a Lorem Ipsum passage, and going through the cites of the word in classical literature, discovered the undoubtable source. Lorem Ipsum comes from sections 1.10.32 and 1.10.33 of de Finibus Bonorum et Malorum (The Extremes of Good and Evil) by Cicero, written in 45 BC. This book is a treatise on the theory of ethics, very popular during the Renaissance. The first line of Lorem Ipsum, Lorem ipsum dolor sit amet.., comes from a line in section 1.10.32
                        "

                 }

          }


}



File: MultiLineText.qml
=====================
import Qt 4.7


Item {

    id:scrollMultiLine
    property string mlt_fontfamily;
    property int mlt_fontSize:18;
   // property alias mlt_dataText: scrollText.text
     property string mlt_dataText;
 //   property alias mlt_color:scrollText.color

    Component.onCompleted:{
        console.log("Target Height="+target_B.height+"  ContentHeight"+target_B.contentHeight)
    }

    Component{
        id:scrollTextDelegate
        Text{
            id:scrollText

            anchors.fill: parent;
            wrapMode:Text.WordWrap;
            font.family: mlt_fontfamily;
            font.pixelSize:0
            text: mlt_dataText;
        }
    }

    ListView{
        id:target_B;
        model: 1; clip: true
        x:0;y:0;
        width: parent.width;height: parent.height;
        delegate:scrollTextDelegate
     }

//    ScrollBar{
//        target: target_B
//    }

}
=====================


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110214/ea7f5cef/attachment-0001.html 


More information about the Qt-qml mailing list