Results 1 to 4 of 4

Thread: QChartView panning feature limit

  1. #1
    Join Date
    Apr 2021
    Posts
    27
    Thanks
    5

    Default QChartView panning feature limit

    I have implemented a Line Graph using QChartView.

    In this graph, I have implemented a panning feature. Code for panning is given as follows.

    void ChartView::keyPressEvent(QKeyEvent *event)
    {
    switch (event->key()) {
    case Qt::Key_Left:
    chart()->scroll(-10, 0);
    break;

    case Qt::Key_Right:
    chart()->scroll(10, 0);
    break;

    default:
    QGraphicsView::keyPressEvent(event);
    break;
    }
    }
    The panning feature is working.

    However, I want to add limits to panning like 0 ~ 500000. Once the graph axis reaches 500000, panning should stop.
    Any suggestions?
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,018
    Thanks
    280
    Thanked 816 Times in 805 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QChartView panning feature limit

    Once the graph axis reaches 500000, panning should stop.
    Any suggestions?
    It seems sort of obvious to me - in your keyPressEvent() handler, calculate what the current axis left and right values are, and if they are less than 0 or > 500000, then do not call the scroll() method.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Apr 2021
    Posts
    27
    Thanks
    5

    Default Re: QChartView panning feature limit

    I was also thinking the same thing. But how can I get the current axis left and right values?

    I couldn't find any function in the QChart documentation, Which would give me the current axis values.

    Do you know any Qchart method that I can use?

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,018
    Thanks
    280
    Thanked 816 Times in 805 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: QChartView panning feature limit

    Do you know any Qchart method that I can use?
    QChartView::axes() and QValueAxis::min() and QValueAxis::max() seem like good places to start.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Problem with implementing custom QChartView
    By Mohsin in forum Qt Programming
    Replies: 3
    Last Post: 14th May 2021, 16:50
  2. adding new QChart in a QChartView
    By zemlemer in forum Newbie
    Replies: 3
    Last Post: 7th September 2019, 16:02
  3. Frameless QChart in QChartview not possible?
    By mustermann.klaus@gmx.de in forum Qt Programming
    Replies: 0
    Last Post: 5th May 2019, 16:29
  4. Save QChartView as PNG
    By Carlsberg in forum Qt Programming
    Replies: 1
    Last Post: 24th June 2017, 16:44
  5. Problem getting QChartView to display
    By derrickbj in forum Qt Programming
    Replies: 5
    Last Post: 20th September 2016, 16:55

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.