Results 1 to 13 of 13

Thread: QSlider Iteration Misses Sample Data on QCustomPlot

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2021
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    Hi,
    As you stated, I removed the check of "diff < 0,01" to handle the last slider correctly. Additionally, 0 - 1000 range setting just worked. But after 5 times zoom, when the range size decreases, data miss problem still exists with one iteration of QSlider.
    I mean, when "the range size" is smaller than "the range which corresponds to one slider move", data miss problem occurs. And this statement emerges when 5-6 times zoom made. Do you have any suggestion to manage this situation ?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,313
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    Do you have any suggestion to manage this situation ?
    I think you need to look at the calculations you are doing. It sounds to me like you are dividing the unzoomed axis range by 100 or 1000 or whatever. If you do that, you will eventually reach the point you get to - the precision of the slider is less than the current zoom range, so there are areas that get skipped.

    I don't really know how you want this zoom feature to behave so it is hard for me to suggest a solution.
    <=== 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
    Jan 2021
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    Hi again,

    Lets say our record is 40 seconds.. QSlider range is 0-1000, and I set the range of slider at initialization, not dynamically. So in this case one move of slider is equal to 0,04 seconds. When a lot of zooms are made, the difference btw lower and upper range is smaller than one move size (0.04 seconds). That's why areas are skipped .. Isn't there any way of changing "area size of one qslider move" ? If the area corresponding to the one qslider move decreases, my problem will be resolved. Do you still think DoubleSlider widget is not a solution ?

    Thanks in advance,
    Kind Regards
    Last edited by cranberriess89; 22nd January 2021 at 10:17.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,313
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    So in this case one move of slider is equal to 0,04 seconds.
    That's what I suspected - you are using the unzoomed (full) range of your data to set the slider increment.

    Each time you zoom in (or out), you need to reset the mapping between slider value and range so that it matches the current zoomed-in range. So if the initial range is 0 - 40 seconds, and you zoom in by 2x around the center, then the new range is 10 - 30 seconds. The next step halves that again, to 15 - 25 seconds, and so on. You can probably change the slider range to something like 0 - 10 or 0 - 20 steps, so at most you can zoom in by 2^20 if each step zooms by 2x. If a 2x zoom for each step is too much, then use a smaller factor - 1.5 - but not less than 1.0 (which is no zoom at all).
    <=== 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.

  5. #5
    Join Date
    Jan 2021
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    As you realized, I should update the value of one move of QSlider dynamically when zoomed. As fas as I examined, “One QSlider Move = QCustomPlot Range Size/ QSlider Maximum Width"
    For every zoom, I already update the range of QCustomPlot and value of QSlider but somehow "One QSlider Move" not updated. Is this a bug of QSlider ? I traced logs but after zoom operation, one move iteration width is the same with not zoomed one ( 0.04 seconds ). Do you know the way of updating one move iteration value dynamically ?

    There is a setter of QSlider, setSingleStep(int). I thought I can set it dynamically when zoomed, but it takes only integer values..
    Last edited by cranberriess89; 25th January 2021 at 15:10.

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,313
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    Is this a bug of QSlider ?
    No, it is a bug in your logic. You need to compute the zoom factor after each step, and use that new factor to scale the plot for the next step. You do not need to change the slider range, ever. What you need to change is how your code translates the current slider value and current plot range into a new width in seconds.

    You probably should post your complete code for how you are doing your zoom operation, and explain in detail what should happen to the plot each time the user moves the slider one step.
    <=== 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.

  7. #7
    Join Date
    Jan 2021
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    For every zoom, xAxisChanged slot is triggered. So I set new range and values to increase the precision of QSlider, but it didn't work. When range size of QCustomPlot is smaller than one iteration width of QSlider, some areas get skipped.
    Qt Code:
    1. View::View(QWidget *parent) :
    2. AbstractMainWindow(parent),
    3. ui(new Ui::View)
    4. {
    5. precision = 1000.0;
    6. /* ui->horizontalScrollBar = QSlider*/
    7. ui->horizontalScrollBar->setTracking(true);
    8. ui->horizontalScrollBar->setVisible(false);
    9. ui->horizontalScrollBar->setMinimum(0);
    10. ui->horizontalScrollBar->setMaximum(precision);
    11. }
    12.  
    13. void View::horzScrollBarChanged(int value)
    14. {
    15. double ratio = (double)value/(double)(ui->horizontalScrollBar->maximum());
    16. double val = ratio*graphmaxValue;
    17. qDebug()<<"horzScrollBarChanged value : " <<val << "range size:"<< plot->xAxis->range().size();
    18. qDebug()<<"horzScrollBarChanged range : " << plot->xAxis->range();
    19.  
    20. plot->xAxis->setRange(val, plot->xAxis->range().size(), Qt::AlignCenter);
    21. plot->replot();
    22.  
    23. }
    24.  
    25. void View::xAxisChanged(QCPRange range)
    26. {
    27. qDebug()<<"xAxisChanged : range " <<range << "range size:" <<range.size() << "range center:" << range.center();
    28. int value = qRound((range.center()*precision)/graphmaxValue);
    29.  
    30. double currentRangeSize = range.size();
    31. /* initialRangeSize is set when the plot is loaded firstly */
    32. double ratio = currentRangeSize*1000/initialRangeSize;
    33. int newSliderMaximum = (ratio)*1000;
    34.  
    35. ui->horizontalScrollBar->setMaximum(newSliderMaximum);
    36. ui->horizontalScrollBar->adjustSize();
    37.  
    38. qDebug()<<"xAxisChanged horzScrollBar max: " << ui->horizontalScrollBar->maximum();
    39.  
    40. int newRangeValue = (value/1000.0)*(ui->horizontalScrollBar->maximum());
    41. ui->horizontalScrollBar->setValue(newRangeValue);
    42.  
    43. }
    To copy to clipboard, switch view to plain text mode 

  8. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,313
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    increase the precision of QSlider
    You keep referring to QSlider, but your code indicates a horizontal scrollbar. Which is it?
    <=== 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.

  9. #9
    Join Date
    Jan 2021
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QSlider Iteration Misses Sample Data on QCustomPlot

    It is QSlider, "ui->horizontalScrollBar" is an instance of QSlider..
    Last edited by cranberriess89; 27th January 2021 at 08:50.

Similar Threads

  1. QSlider Iteration Misses Sample Data on QCustomPlot
    By cranberriess89 in forum Qt Programming
    Replies: 1
    Last Post: 18th January 2021, 17:19
  2. Replies: 1
    Last Post: 2nd March 2020, 17:11
  3. How to implement Warp7 sample as same as sample in QtWS16
    By nntchau in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 8th December 2017, 08:06
  4. Serial read misses to read data from the serial port
    By mania in forum Qt for Embedded and Mobile
    Replies: 11
    Last Post: 18th August 2014, 08:49
  5. Replies: 16
    Last Post: 27th March 2013, 06:23

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
  •  
Qt is a trademark of The Qt Company.