QCustomPlot Discussion and Comments

Example of QCPAxisRect::setRangeDragReturn to overview

Hi, i'm new in QT.
i want to Set dragging for only xAxis in my chart. Apparently i shall use QCPAxisRect::setRangeDrag and Qt::Horizontal .
but [ui->customPlot->setInteractions(QCPAxisRect::setRangeDrag | Qt::Horizontal);]
is false.
Please Help Me!
thanks.

Use the following steps :

ui->customPlot->setInteractions(QCP::iRangeDrag);

and then on the QCPAxisRect you want to drag, you have to call:

ui->customPlot->axisRects().at(0)->setRangeDrag(Qt::Horizontal);

thanks,it works Fine.
for adding a Horizontal scrollbar In addition to the mouse drag ,
what i can do !?
in this link , a axis Controlling range with a scrollbaris decribed. but with Signal and slot and i dont understand it.
is there any other simple way?
thanks

http://www.qcustomplot.com/index.php/tutorials/specialcases/scrollbar

Even shorter:

ui->customPlot->axisRect(0)->setRangeDrag(Qt::Horizontal);

and even more shorter for the main rect :)

ui->customPlot->axisRect()->setRangeDrag(Qt::Horizontal);

I think the tutorial is already simple...

continiue!
in your code sample, how i can limit draging for example from 0 to 100?

if realy it is simple, i will try the tutorial more.thanks
but the problem of limiting draging range!
do you have any solution to fix it?

The documentation of rangeChanged signal has that example for range limiting.
http://www.qcustomplot.com/documentation/classQCPAxis.html#a0894084e4c16a1736534c4095746f910
I think it has also been asked a few times here in the forum.

Isso is right! There's a few post on the forum that explain how to limit the range. You should make a quick search !

And I suggest you to get familiar with SIGNAL/SLOT since Qt is based on those.

For example, you could just create your own class that inherit from QCustomPlot, and create a function like :

void YourOwnClass::setRange(QCPRange range){

    for(int i=0; i<this->axisRects().size(); i++ ){
        if(range.lower<0)
            this->axisRect(i)->axis(QCPAxis::atBottom)->setRange (0,range.upper);
        else
            this->axisRect(i)->axis(QCPAxis::atBottom)->setRange(range);
    }

}

and connect the SIGNAL "rangeChanged" of your axis to this SLOT(function). In this case, the axis won't go below 0.