Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Scroll inside ChartView QML
QtWS25 Last Chance

Scroll inside ChartView QML

Scheduled Pinned Locked Moved Solved QML and Qt Quick
3 Posts 2 Posters 1.4k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    ENSAO_CHEIKH
    wrote on last edited by
    #1

    Hi EveryOne, so in my project I'm trying to create Chartview dynamically using repeater so I want to use a ScrollView for that how to do it?, also inside this ChartView in the axis X I want have an horizontal Scoll so that I can scroll the axis X is there any solution for that please?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      ENSAO_CHEIKH
      wrote on last edited by
      #2

      any solution pleaaaaaaaaase

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jay1
        wrote on last edited by jay1
        #3

        From what I understand from your question is that you want to add the horizontal scroll to your chart.
        From my point of view "ScrollView" can be of less value if you want to scroll inside the chart.
        ScrollView can be usefull when you want to scroll across multiple charts in this scenario.

        Here is a sample code that shows how to implement horizontal scroll for one chart. Hope you can implement for multiple charts.

        When you press the left mouse button and move the mouse the scroll function is implemented (you change this logic to any other function)

        Item {
            id: root
            anchors.fill: parent
        
            ChartView {
                id: chartViewItem
                antialiasing: true
                anchors.fill: parent
        
                LineSeries {
                    id: lineSeriesChart
                    name: "Random Data"
                    XYPoint { x: 0; y: 0 }
                    XYPoint { x: 10; y: 12 }
                    XYPoint { x: 20; y: 32 }
                    XYPoint { x: 30; y: 25 }
                    XYPoint { x: 40; y: 14 }
                    XYPoint { x: 50; y: 39 }
                    XYPoint { x: 60; y: 53 }
                    XYPoint { x: 70; y: 0 }
                    XYPoint { x: 80; y: 12 }
                    XYPoint { x: 90; y: 32 }
                    XYPoint { x: 100; y: 25 }
                    XYPoint { x: 110; y: 14 }
                    XYPoint { x: 120; y: 39 }
                    XYPoint { x: 130; y: 53 }
                 }
        
                Rectangle {
                    id: horizontalScrollMask
                    visible: false
                }
        
                MouseArea {
                    id: chartMouseAreaA
                    anchors.fill: parent
                    acceptedButtons: Qt.LeftButton
        
                    onMouseXChanged: {
                        if ((mouse.buttons & Qt.LeftButton) == Qt.LeftButton) {
                            chartViewItem.scrollLeft(mouseX - horizontalScrollMask.x);
                            horizontalScrollMask.x = mouseX;
                        }
                    }
                    onPressed: {
                        if (mouse.button == Qt.LeftButton) {
                            horizontalScrollMask.x = mouseX;
                        }
                    }
                }
            }
        }
        

        saa3.png

        1 Reply Last reply
        1

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved