lundi 20 avril 2015

ScrollView and Canvas in QML

Good day! I'm trying to display multiple charts in different tabs, using Canvas. The scale of the graphs will be somewhat greater than the actual size of the display, so I want to use ScrollView. Have this code in several files:

main.qml:

TabView {
    id: tabView
    Layout.alignment: Qt.AlignCenter
    Layout.fillWidth: true
    Layout.fillHeight: true

    Tab1 {
        id: tab1
    }

    //...
}

Tab1.qml:

Tab {
    active: true

    function init()
    {
        item.plot.requestPaint()
    }

    ScrollView {
        property var plot: _plot
        Plot {
            width: 3000
            id: _plot
        }
    }
}

Plot.qml:

Canvas {
    function draw()
    {
        console.log("draw go")
        var ctx = getContext("2d")
        ctx.reset()

        //...
    }

    onPaint: {
        draw()
    }
}

At some point, the function is called init(). The problem is that when using ScrollView signal Paint is not called, without ScrollView everything works well. Errors in the console does not arise. Qt 5.4.1

Aucun commentaire:

Enregistrer un commentaire