I want change the axis range when I click the widget. But sometimes I act strangely. I don't know the reason.
Here is the code and some strange result.

void myClass::onMousePressed(QMouseEvent *event)
{
    if(m_bZoomin)
    {
        ui->widgetCurveGraph->xAxis->setRange(0, m_nMaxCount);
        QSharedPointer<QCPAxisTickerFixed> tickerCard(new QCPAxisTickerFixed);
        tickerCard->setTickStep(128);
        ui->widgetCurveGraph->xAxis->setTicker(tickerCard);
        m_bZoomin = false;
    }
    else
    {
        float fX = ui->widgetCurveGraph->xAxis->pixelToCoord(event->pos().x());
        float fY = ui->widgetCurveGraph->yAxis->pixelToCoord(event->pos().y());
        if(fY >= 0 && fY <= 65535)
        {
            if(fX >= 0 && fX <= m_nMaxCount)
            {
                int nIndex = fX / 128;
                ui->widgetCurveGraph->xAxis->setRange(nIndex * 128, (nIndex + 1) * 128);
                QSharedPointer<QCPAxisTickerFixed> tickerCard(new QCPAxisTickerFixed);
                tickerCard->setTickStep(8);
                ui->widgetCurveGraph->xAxis->setTicker(tickerCard);
                m_bZoomin = true;
            }
        }
    }
    ui->widgetCurveGraph->replot();
}

How to attach image?