0
I use QSlider and QCustomPlot widgets together in the project. It works ok generally but when I iterate QSlider once ( single iteration ) after zooming on QCustomPlot a few times( range size decreases), some data missed and can not be examined in detail. Lets say previous x axis range (10:20:000 – 10:20:300), the next range after iteration becomes (10:20:460 - 10:20:760 ). So, 160 miliseconds could not be seen. In this context, my implementation is as follows;
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(horzScrollBarChanged(int)));
connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange)));
void MainWindow::horzScrollBarChanged(int value)
{
if (qAbs(ui->plot->xAxis->range().center()-value/100.0) > 0.01) // if user is dragging plot, we don't want to replot twice
{
ui->plot->xAxis->setRange(value/100.0, ui->plot->xAxis->range().size(), Qt::AlignCenter);
ui->plot->replot();
}
}
void MainWindow::xAxisChanged(QCPRange range)
{
ui->horizontalScrollBar->setValue(qRound(range.center()*100.0)); // adjust position of scroll bar slider
ui->horizontalScrollBar->setPageStep(qRound(range.size()*100.0)); // adjust size of scroll bar slider
}
connect(ui->horizontalScrollBar, SIGNAL(valueChanged(int)), this, SLOT(horzScrollBarChanged(int)));
connect(ui->plot->xAxis, SIGNAL(rangeChanged(QCPRange)), this, SLOT(xAxisChanged(QCPRange)));
void MainWindow::horzScrollBarChanged(int value)
{
if (qAbs(ui->plot->xAxis->range().center()-value/100.0) > 0.01) // if user is dragging plot, we don't want to replot twice
{
ui->plot->xAxis->setRange(value/100.0, ui->plot->xAxis->range().size(), Qt::AlignCenter);
ui->plot->replot();
}
}
void MainWindow::xAxisChanged(QCPRange range)
{
ui->horizontalScrollBar->setValue(qRound(range.center()*100.0)); // adjust position of scroll bar slider
ui->horizontalScrollBar->setPageStep(qRound(range.size()*100.0)); // adjust size of scroll bar slider
}
To copy to clipboard, switch view to plain text mode
Could you please help about this problem ?
Thanks in advance for your replies..
Bookmarks