Results 1 to 18 of 18

Thread: Axis yLeft cuts of numbers

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 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

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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

  3. #3
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 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.

  4. #4
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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

  5. #5
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 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

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    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

  7. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,312
    Thanked 879 Times in 827 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

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

    Ban-chan (9th October 2009)

  9. #8
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Axis yLeft cuts of numbers

    Thanks, Uwe.

  10. #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

    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.