Results 1 to 6 of 6

Thread: Scale displayed incorrectly

  1. #1
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Scale displayed incorrectly

    I think I discovered a bug in the way that the scale is displayed.

    I have an example program with a bare QwtPlot and a checkbox that sets/clears the attribute QwtScaleEngine::Floating for the x axis. Here is the code:

    Qt Code:
    1. QtDialogTest::QtDialogTest(QWidget* parent)
    2. : QDialog(parent)
    3. {
    4. ui.setupUi(this);
    5. Populate();
    6. ui.plot->setAxisAutoScale(QwtPlot::xBottom);
    7. connect(ui.enableFloatingAttributecheckBox, &QCheckBox::stateChanged, this, &QtDialogTest::EnableFloatingAttribute);
    8. }
    9.  
    10. void QtDialogTest::EnableFloatingAttribute(int state)
    11. {
    12. bool enable = (state == Qt::Checked);
    13. ui.plot->axisScaleEngine(QwtPlot::xBottom)->setAttribute(QwtScaleEngine::Floating, enable);
    14. ui.plot->replot();
    15. }
    16.  
    17. void QtDialogTest::Populate()
    18. {
    19. QVector<QPointF> samples{ QPointF(1000.4, 1.0), QPointF(1001.4, 1.5), QPointF(1001.7, 2.0), QPointF(1001.9, 1.5), QPointF(1002.05, 1.0) };
    20. auto curve = new QwtPlotCurve;
    21. curve->setSamples(samples);
    22. QBrush brush(QColor::fromRgb(255, 0, 0));
    23. QPen pen(QColor::fromRgb(128, 0, 0));
    24. curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse, brush, pen, QSize(8, 8)));
    25. curve->setPen(pen);
    26. curve->attach(ui.plot);
    27. }
    To copy to clipboard, switch view to plain text mode 

    When the plot is displayed, everything seems ok (see attached file ScaleOk.png). However, when I reduce the size of the plot, the scale is not displayed correctly anymore (see attached file ScaleWrong.png). I guess the plot attempts to display the leftmost label of the scale and - correctly - reduced the space between the ticks. But since the leftmost data point has a value of 1000.4, which also is the value of the leftmost minor tick, these two are not displayed correctly to each other anymore.

    Can you perhaps provide a short-term bugfix for this?
    Attached Images Attached Images

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scale displayed incorrectly

    From the screen shots alone it is hard to say anything useful. Could you create a small and compilable demo where I can debug the situation ?

    Uwe

  3. #3
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Scale displayed incorrectly

    Sure, see attachment (QwtPlotTest.zip). It includes a dialog class with a QwtPlot widget. When you run the example, resize the dialog by its right border. When the dialog is small enough, you'll see the problem.

    As far as I can tell, the problem is that the scale (the x scale in this example) always displays the leftmost number. However, if the number does not fit anymore between the adjecting (minor) ticks, things start to get wrong. The space between the ticks is reduced, but since the leftmost number must still be displayed, the leftmost minor tick starts to move to the right. That is not wrong per se, but the data point is not moved along with the minor tick. Please note that the leftmost data point in my example is exactly the same value as the leftmost minor tick. So when the tick moves, the data point should move, too.

    This error does not show when the scale engine attribute QwtScaleEngine::Floating is not set, but unfortunatly that is no option for us.
    Attached Files Attached Files

  4. #4
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Scale displayed incorrectly

    Uwe,
    did you find something...?

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,311
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Scale displayed incorrectly

    It's a problem of a missing updates of the axes border distances not being called from QwtPlot::resizeEvent. Fixed in SVN ( all branches >= 6.1 ).
    If you don't want to upgrade the following workaround can be done in application code:

    Qt Code:
    1. virtual void YourPlot::updateLayout override
    2. {
    3. QwtPlot::updateLayout();
    4.  
    5. for ( int axisId = 0; axisId < axisCnt; axisId++ )
    6. {
    7. if ( axisEnabled( axisId ) )
    8. {
    9. QwtScaleWidget* scaleWidget = axisWidget( axisId );
    10.  
    11. int startDist, endDist;
    12. scaleWidget->getBorderDistHint( startDist, endDist );
    13. scaleWidget->setBorderDist( startDist, endDist );
    14. }
    15. }
    16. }
    To copy to clipboard, switch view to plain text mode 
    Uwe

  6. The following user says thank you to Uwe for this useful post:

    Crowley (27th March 2017)

  7. #6
    Join Date
    Oct 2012
    Posts
    12
    Thanks
    3
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Scale displayed incorrectly

    Works perfectly, thanx. :-)

Similar Threads

  1. Qt Quick output is displaying incorrectly after compile
    By rostamiani in forum Qt for Embedded and Mobile
    Replies: 1
    Last Post: 7th June 2015, 08:04
  2. Qt SvgRenderer renders SVG incorrectly
    By Daevius in forum Qt Programming
    Replies: 0
    Last Post: 2nd October 2011, 16:40
  3. QtSVG build incorrectly
    By Helios in forum Installation and Deployment
    Replies: 0
    Last Post: 11th July 2010, 05:58
  4. Load image from QNetworkReply incorrectly
    By tqlong in forum Qt Programming
    Replies: 0
    Last Post: 1st July 2010, 16:51
  5. Replies: 1
    Last Post: 24th June 2010, 15:00

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.