Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Native Development

Reply
Highlighted
New Contributor
Posts: 6
Registered: ‎12-23-2012
My Device: Playbook 2.0
My Carrier: MegaFon RUS
Accepted Solution

Qml perfomance

Hello. I have a problem with qt on playbook. I have successfully created a simple reader for PB, using qml technology, but when I scroll text, I have annoying lags. I have taken a video of that: http://youtu.be/FW0JkUR4rQA

The elemnt, which is lagging, is a flickable element with custom rectanges inside it. There is a code:


 

    Flickable {
        property int myBottomMargin: 0
            id: flick
            anchors.rightMargin: 0
            anchors.bottomMargin: myBottomMargin
            anchors.leftMargin: 250
            anchors.topMargin: 48
            z: 1
            flickableDirection: Flickable.VerticalFlick
            contentWidth: 517
            contentHeight: 0
            interactive: true
            clip: true
            anchors.fill: parent
    }

 


 

 

Objects that are in it use that class:

import QtQuick 1.1


Rectangle {
    id: story
    property alias storyText : joke.text
    property alias idText : id.text
    property alias dateText : date.text
    property alias ratioText : ratio.text
    //transformOrigin: Item.TopLeft
    width: topLine.width
    height: topLine.height + border_image1.height

    Image {
        id: topLine
        x: 0
        y: 0
        source: "../quite_top.png"

        Image {
            id: image1
            x: 20
            y: 4
            width: 21
            height: 18
            source: "../up.png"
        }

        BorderImage {
            id: border_image1
            x: 0
            y: topLine.height + topLine.y
            width: topLine.width
            height: joke.paintedHeight
            border.top: 0
            border.right: 633
            border.left: 633
            z: -1
            source: "../quite_middle.png"
        }

        Text {
            id: joke
            x: 20
            y: topLine.height + topLine.y
            //+topLine.width*0.05
            width: border_image1.width-40
            height: 200
            font.family: "Times New Roman"
            //text: qsTr("good joke")
            wrapMode: Text.WrapAtWordBoundaryOrAnywhere
            font.pixelSize: 18
        }

        Image {
            id: bottomLine
            x: 0
            y: joke.paintedHeight + joke.y
            source: "../quite_bottom.png"
        }

        Text {
            id: id
            x: 497
            y: 6
            width: 116
            height: 14
            text: qsTr("")
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignRight
            font.pixelSize: 12
        }

        Text {
            id: date
            x: 327
            y: 6
            text: qsTr("")
            verticalAlignment: Text.AlignVCenter
            font.pixelSize: 12
        }

        Text {
            id: ratio
            x: 49
            y: 6
            text: qsTr("")
            verticalAlignment: Text.AlignVCenter
            horizontalAlignment: Text.AlignLeft
            font.pixelSize: 12
        }

    }
}

 


 

And how I full the list:

function addObjects() {
    console.log("Add objects")
    console.log(data[0][0])

    setStatusBarText();

    isLoading = false

    count = data[0].length

    var component = Qt.createComponent("Story.qml")
    var height_flick = y_offset

    //console.log(data[0][0]);
    for (var i=0;i<count;i++) {
        objects[i] = component.createObject(flick.contentItem, {
                                                    "x": x_offset,
                                                    "y": 0
                                            });
        if (i!=0) {
            objects[i].y = height_flick+objects[i-1].height + y_offset;
            height_flick = objects[i].y
        }
        objects[i].storyText = data[0][i]
        objects[i].idText = data[1][i]
        objects[i].ratioText = data[2][i]
        objects[i].dateText = data[3][i]
    }

    //console.log("min_value ",data[4])
    if (data[4]) {
        slider_page.min_value = data[4]
        slider_page.max_value = 1
    }

    flick.contentHeight = objects[count-1].y+objects[count-1].height + y_offset;

}

 

I use Qt 4.8.3 with default settings if it is matter. Thanks

 

Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Qml perfomance

Hi,

Flickable isn't optimized for displaying many elements.

It's better to use a ListView with delegate & dataModel. ListView creates only the elements which are currently on screen and should work very fast.

Andrey Fidrya, @zmeyc on twitter
New Contributor
Posts: 6
Registered: ‎12-23-2012
My Device: Playbook 2.0
My Carrier: MegaFon RUS

Re: Qml perfomance

I thought about that, but as I know, ListView shows elements with constant height, but my elements in the list can range in height.
Developer
Posts: 1,524
Registered: ‎12-18-2012
My Device: Z30, Z10 LE, DevAlpha C, PlayBook

Re: Qml perfomance

I've created a test project and it seems that ListView can have elements of varying height. Haven't tried this with Qt Quick 1.0, but I guess it should work too.

 

 

import QtQuick 2.0

Rectangle {
    width: 1024
    height: 768

    ListModel {
        id: model1

        ListElement {
            elementColor: "red"
            elementHeight: 50
        }
        ListElement {
            elementColor: "green"
            elementHeight: 100
        }
        ListElement {
            elementColor: "blue"
            elementHeight: 30
        }
    }
    ListView {
        anchors.fill: parent

        model: model1
        delegate: Component {
            Rectangle {
                color: elementColor
                width: 100
                height: elementHeight
                Text {
                    text: elementColor
                }
            }
        }
    }
}

 


Andrey Fidrya, @zmeyc on twitter