Results 1 to 18 of 18

Thread: Axis yLeft cuts of numbers

  1. #1
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Axis yLeft cuts of numbers

    Hi,

    I use a manually settable Y Axis on my custom QwtPlot.
    It now sometimes occurs, that the values shown on the left arr cut at the beginning.
    so 10000000 will be shown okay, because it takes the place it needs from the plot,
    but 60000 or bigger (5,6,4) numbers will be cut of some pixels on the left.

    Is this a Layout problem or is there something I have to do with qwt?

    Thanks!
    sun
    Last edited by sun; 8th October 2008 at 16:31.

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

    Default Re: Axis yLeft cuts of numbers

    The layout engine calculates the space, that is needed for the tick labels and always gives the scales enough space for them. When your labels are cut off I guess, that the layout was not recalculated after changing the tick labels.

    F.e. resizing the plot widget forces a recalculation of the layout. What happens to your labels, when you manually do this ?

    Uwe

  3. #3
    Join Date
    Sep 2008
    Posts
    17
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Axis yLeft cuts of numbers

    Hi,

    I'm not absolutely shure if I understood what you wanted me to do.
    The Code that changes the yLeft axis looks as follows.

    Qt Code:
    1. valuePlot->setYAxisScale((valuePlot->getYAxisHigh()-valuePlot->getYAxisLow())/10);
    2. valuePlot->setAxisScale(QwtPlot::yLeft, valuePlot->getYAxisLow(), valuePlot->getYAxisHigh(), valuePlot->getYAxisScale());
    3. valuePlot->updateLayout();
    To copy to clipboard, switch view to plain text mode 
    So I set the Scale of my valuePlot (inherits QwtPlot) and I believe you wanted me to call the updateLayout manually on my value Plot.
    It did not help. Even a mere 6 is shown cut off.

    My valuePlot was in a frame and y updated the layout of this frame. This doesn't help either!

    Did I get you right?

    Thanks
    sun

  4. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Axis yLeft cuts of numbers

    Quote Originally Posted by sun View Post
    I'm not absolutely shure if I understood what you wanted me to do.
    a) Enable a frame for your plot widget ( setFrameStyle + setLineWidth ) and check if the frame is completely visible. If not the reason for your problem is somewhere in the layout of your main window.

    b) When the tick labels are cut off use your mouse and resize the main window manually. When the labels are visible after resizing we know, that a layout recalculation was missing.

    Uwe

  5. #5
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Axis yLeft cuts of numbers

    I have seen this problem also. When the QwtPlot is inserted in a dialog (in my case, in a vertical layout), and there is -no- yLeft axis title, the left-most digits of long tick labels get clipped a little bit. If there is a yLeft title, this does not happen, since the title contains enough extra space to avoid clipping.

    I think this is a layout problem for QwtPlot, not for our applications. When I dynamically change the axis range the labels get recalculated (and the canvas size changes if needed), but once the number of digits gets high enough (> 4 digits), the clipping starts to occur. Resizing the window does not fix the clipping problem.

    David

  6. #6
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Axis yLeft cuts of numbers

    When the plot is resized the layout is recalculated. So the problem can't be a missing recalculation and should be somewhere inside the layout calculation. For the plot layout engine the number of digits is completely unimportant - the scale simply gets the size it needs. I've tried a couple of intervals myself and couldn't see any clipping.

    Maybe the problem is in the calculation of the bounding rect for the tick label itsself - what might be platform or font dependent.

    Could you change your application this way:

    Qt Code:
    1. class YourScaleDraw: public QwtScaleDraw
    2. {
    3. ...
    4.  
    5. virtual QwtText label(double value) const
    6. {
    7. QwtText tickLabel = QwtScaleDraw::label(value);
    8. tickLabel.setBackgroundPen(Qt::red);
    9. return tickLabel;
    10. }
    11. };
    To copy to clipboard, switch view to plain text mode 

    Assign YourScaleDraw for the left axis - now there should be a frame around all tick labels. What happens to the frame in the situation, when the labels are cut off ?

    Another test you could do is to change the font. F.e. what happens, when you use a fixed font like Courier.

    Uwe

  7. #7
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Axis yLeft cuts of numbers

    Hi Uwe,

    myPlot->setAxisScale( QwtPlot::yLeft, 0, 8000 );
    myPlot->setAxisScaleDraw( QwtPlot::yLeft, new YourScaleDraw );

    The red box is clipped at the left, along with a few pixels of the left-most digit.
    This is on Windows. I have no way to test on other platforms.

    myPlot->setAxisScale( QwtPlot::yLeft, 0, 10000 );

    This also clips the box to the left of the 10000; all other boxes are OK as expected.

    Regards,

    David

  8. #8
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Axis yLeft cuts of numbers

    Unfortunately I can't reproduce the problem. I'm afraid you need to send me code for a short application demonstrating the problem.

    Uwe

  9. #9
    Join Date
    May 2009
    Posts
    20
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Axis yLeft cuts of numbers

    I know this is an old thread but was this issue ever resolved? I have the same effect happening on my yLeft axis except for when a yAxis title is set. When I changed the font from the default (which I think is Helvetica) to Courier, this clipping no longer occurred.

  10. #10
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Axis yLeft cuts of numbers

    Quote Originally Posted by Ban-chan View Post
    I know this is an old thread but was this issue ever resolved?
    Nobody ever sent me a demo for debugging the problem,

    Uwe

  11. #11
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Axis yLeft cuts of numbers

    Here you go Uwe:

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QMainWindow>
    3. #include <qwt_plot.h>
    4.  
    5. int main(int argc, char *argv[])
    6. {
    7. QApplication a(argc, argv);
    8. QwtPlot * pPlot = new QwtPlot;
    9. pPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0e8, 5.0e6 );
    10. w.setCentralWidget( pPlot );
    11. w.resize( 500, 500 );
    12. w.show();
    13. return a.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    All of the x.5e7 labels are clipped on the left side by a couple of pixels. If the screenshot I will try to attach shows up, you can easily see this. This is Windows XP, Qt 4.5, Qwt 5.2.0, Visual C++ 2008. i have no way to test on another platform.

    David
    Attached Images Attached Images

  12. #12
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Axis yLeft cuts of numbers

    Well, your code works fine in my environment. The main problem of this bug is, that it seems to be platform and font depending. Unfortunately the font is derived from your environment ( or depends on the font matching algo ) and not known from your code. So please do the following in your environment: assign a scale draw object to the left axis, where you return text labels with a frame. ( QwtText::setBackgroundPen() ).

    When the frame is cut off it should be a problem of the layout code - if not ( what I expect ), there is a mismatch between calculating the bounding rect for the text and what is used for painting. The next step would be to strip down the code from QwtText::draw() and QwtPlainTextEngine::textSize() and QwtPlainTextEngine::textMargins() to a small demo, that paints a text to a QWidget without using Qwt.

    Uwe

    PS: subclassing QwtPlainTextEngine + returning left/right margins in YourPlainTextEngine::textMargins() might be a workaround for the bug.

  13. #13
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Axis yLeft cuts of numbers

    Hi Uwe,

    OK, a little bigger example, with a custom QwtAxisScaleDraw for the yLeft axis. As you can see from the screenshot, the left side of most of the boxes is clippped.

    What next?

    Regards,
    David

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include <QMainWindow>
    3. #include <QPainter>
    4. #include <QPen>
    5. #include <qwt_plot.h>
    6. #include <qwt_scale_draw.h>
    7. #include <qwt_text.h>
    8. #include <qwt_painter.h>
    9. #include <qwt_math.h>
    10.  
    11. #if QT_VERSION < 0x040000
    12. #include <qwmatrix.h>
    13. #define QwtMatrix QWMatrix
    14. #else
    15. #include <qmatrix.h>
    16. #define QwtMatrix QMatrix
    17. #endif
    18.  
    19. class MyScaleDraw
    20. : public QwtScaleDraw
    21. {
    22. public:
    23. MyScaleDraw() {}
    24.  
    25. protected:
    26. virtual void drawLabel( QPainter * painter, double value ) const
    27. {
    28. QwtText lbl = tickLabel(painter->font(), value);
    29. if ( lbl.isEmpty() )
    30. return;
    31.  
    32. lbl.setBackgroundPen( QPen( Qt::black ) );
    33. QPoint pos = labelPosition(value);
    34.  
    35. QSize labelSize = lbl.textSize(painter->font());
    36. if ( labelSize.height() % 2 )
    37. labelSize.setHeight(labelSize.height() + 1);
    38.  
    39. const QwtMetricsMap metricsMap = QwtPainter::metricsMap();
    40. QwtPainter::resetMetricsMap();
    41.  
    42. labelSize = metricsMap.layoutToDevice(labelSize);
    43. pos = metricsMap.layoutToDevice(pos);
    44.  
    45. const QwtMatrix m = labelMatrix( pos, labelSize);
    46.  
    47. painter->save();
    48. #if QT_VERSION < 0x040000
    49. painter->setWorldMatrix(m, true);
    50. #else
    51. painter->setMatrix(m, true);
    52. #endif
    53.  
    54. lbl.draw (painter, QRect(QPoint(0, 0), labelSize) );
    55.  
    56. QwtPainter::setMetricsMap(metricsMap); // restore metrics map
    57.  
    58. painter->restore();
    59. }
    60.  
    61. private:
    62. };
    63.  
    64. int main(int argc, char *argv[])
    65. {
    66. QApplication a(argc, argv);
    67.  
    68. QwtPlot * pPlot = new QwtPlot;
    69. pPlot->setAxisScale( QwtPlot::yLeft, 0.0, 1.0e8, 5.0e6 );
    70. pPlot->setAxisScaleDraw( QwtPlot::yLeft, new MyScaleDraw() );
    71.  
    72. w.setCentralWidget( pPlot );
    73. w.resize( 500, 500 );
    74. w.show();
    75. return a.exec();
    76. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  14. #14
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Axis yLeft cuts of numbers

    I tried the following code on my Linux box:

    Qt Code:
    1. #include <QApplication>
    2. #include <QPen>
    3. #include <qwt_plot.h>
    4. #include <qwt_scale_draw.h>
    5.  
    6. class MyScaleDraw: public QwtScaleDraw
    7. {
    8. public:
    9. virtual QwtText label(double value) const
    10. {
    11. QwtText lbl = QwtScaleDraw::label(value);
    12. lbl.setBackgroundPen(QPen(Qt::red));
    13. return lbl;
    14. }
    15. };
    16.  
    17. int main(int argc, char *argv[])
    18. {
    19. QApplication a(argc, argv);
    20.  
    21. QwtPlot pPlot;
    22. pPlot.setAxisScale( QwtPlot::yLeft, 0.0, 1.0e8, 5.0e6 );
    23. pPlot.setAxisScaleDraw( QwtPlot::yLeft, new MyScaleDraw() );
    24.  
    25. pPlot.resize( 500, 500 );
    26. pPlot.show();
    27.  
    28. return a.exec();
    29. }
    To copy to clipboard, switch view to plain text mode 

    Most of the rectangles are visible, but 2 of them are cut off too, what indicates a bug in the Qwt layout code.

    So the next steps are on my side,

    Uwe

  15. #15
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Axis yLeft cuts of numbers

    Hi Uwe,

    Thanks. And thanks for showing me an easier way to demonstrate the problem.

    And by the way, this bug only occurs when the left axis title is null.

    Cheers,

    David

  16. #16
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,258
    Thanked 862 Times in 811 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Axis yLeft cuts of numbers

    The layout code in QwtScaleDraw seems to be wrong by 1 pixel for the left top and right axes. On the left axis it has the effect, that the left axis is cut off by 1 pixel. At least on Linux/X11 the demo seems to be o.k. now.

    Fixed in SVN ( 5.2 + trunk ),

    Uwe

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

    Ban-chan (9th October 2009)

  18. #17
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    4,783
    Thanks
    262
    Thanked 773 Times in 763 Posts
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Axis yLeft cuts of numbers

    Thanks, Uwe.

  19. #18
    Join Date
    May 2009
    Posts
    20
    Thanks
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Axis yLeft cuts of numbers

    Thanks Uwe, works great!

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.