如何工作ChartView :: zoomIn(矩形矩形)

时间:2016-12-16 17:38:46

标签: qt qml qt5 qtquick2

我想在ChartView中使用rectang区域缩放选定内容:

import QtQuick 2.7
import QtCharts 2.1

ChartView{
    id: chart
    width: 400
    height: 400

    ScatterSeries{
        markerSize: 10
        XYPoint{x: 1; y: 1}
        XYPoint{x: 2; y: 2}
        XYPoint{x: 5; y: 5}
    }

    Rectangle{
        id: rectang
        color: "black"
        opacity: 0.6
        visible: false
    }

    MouseArea{
        anchors.fill: parent
        hoverEnabled: true
        acceptedButtons: Qt.AllButtons

        onPressed: {rectang.x = mouseX; rectang.y = mouseY; rectangle.visible = true}
        onMouseXChanged: {rectang.width = mouseX - rectang.x}
        onMouseYChanged: {rectang.height = mouseY - rectang.y}
        onReleased: {
            chart.zoomIn(rectang); // something wrong with that line, it doesn't work
            rectang.visible = false
        } 
    }
}

您能告诉我如何正确使用ChartView::zoomIn(rect rectangle)吗?我希望缩放像Zoom Line Example一样工作。简单ChartView::zoomIn()只需将中心缩放2倍。

1 个答案:

答案 0 :(得分:2)

这有助于:

onReleased: {
        chart.zoomIn(Qt.rect(rectang.x, rectang.y, rectang.width, rectang.height))
        rectang.visible = false
}

我错误地认为rectRectangle属于同一类型。