1 Attachment(s)
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.
Quote:
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?
Re: QChartView panning feature limit
Quote:
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.
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?
Re: QChartView panning feature limit
Quote:
Do you know any Qchart method that I can use?
QChartView::axes() and QValueAxis::min() and QValueAxis::max() seem like good places to start.