Page 2 of 2 FirstFirst 12
Results 21 to 25 of 25

Thread: Problems with QwtPlotRenderer from Qwt 6

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

    Default Re: Problems with QwtPlotRenderer from Qwt 6

    Quote Originally Posted by mariposa View Post
    Unfortunately - even after the SVN update - the exported image is not correctly scaled and the plot is just occupying the upper left quarter.
    Replace the implementation of MainWindow::exportDocument in the bode example with the code I have posted and check the result. Then try to find out what you are doing wrong in your application.

    But this will (as far as I can see it) have the disadvantage that the number of curve points is determined by the size of QRectF( QPointF(0, 0), sz / scaleFactor ). These points are then stretched to the "full" resolution.
    No, not with the double based render engine of Qwt 6.

    My tests using setDotsPerMeterX/setDotsPerMeterY resulted in a curve that has visible "steps" and I assume this will also be the case for your proposed solution.
    When painting to a paint device, that is aligning to integer coordinates (like a QWidget or QImage), Qwt manually rounds certain coordinates - instead of letting Qt floor them. Unfortunately this rounding is based on logical coordinates - not respecting the scale factor of the painter. But this is a bug - not a problem in general.

    When you modify the implementation of QwtPainter::isAligning like below you might have some effects because of the flooring but it should be very close to what you expect.

    Qt Code:
    1. bool QwtPainter::isAligning( QPainter *painter )
    2. {
    3. if ( painter && painter->transform().isScaling() )
    4. return false;
    5.  
    6. ...
    7. }
    To copy to clipboard, switch view to plain text mode 

    Uwe

    PS: Forget about trying to find your code for Qwt5 - you won't succeed. Better try to support the development of Qwt 6

  2. #22
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Problems with QwtPlotRenderer from Qwt 6

    Thank you very much. At first it did not work because (for some reason) after the last SVN co only debug libraries of Qwt were built and therefore the bode example was still linked against the "old" release libraries. But after I modified qwtbuild.pri it worked as expected.

    The result looks the way I want it and after modification of the QwtPainter::isAligning function the "steps" are indeed gone.

    Unfortunately two issues are remaining:
    1) The scaling factor needs to be adjusted according to the desired resolution in order to get reasonably sized plot elements. But it hopefully won't be too difficult for me to find a suitable formula...

    2) The text lables in the resulting graphic look a little bit odd:

    screenshot_text.png

    And the thickness of the lines of the axes (and the grid) doesn't seem to get adjusted. The resulting lines seem to be a little too thin for printing.


    Update: I found a way for getting rid of the scaling factor. In my project I successfully use the following code to generate pixel images that can be of any resolution and always look the same when displayed in the same "real world" size:

    Qt Code:
    1. const double toInch = 1.0 / 25.4; //convert mm to inch
    2.  
    3. //the user is asked for setWidth and setHeight (intended "real world" size in mm)
    4. const QSizeF size = QSizeF(setWidth, setHeight) * toInch * setResolution;
    5. const QRectF documentRect( 0.0, 0.0, size.width(), size.height() );
    6. const qreal toDPM = 1.0 / 0.0254;
    7.  
    8. const QRect imageRect = documentRect.toRect();
    9. QImage image( imageRect.size(), QImage::Format_ARGB32 );
    10.  
    11. //the selected resolution (setResolution) is converted to DotsPerMeter
    12. image.setDotsPerMeterX(setResolution * toDPM);
    13. image.setDotsPerMeterY(setResolution * toDPM);
    14.  
    15. image.fill(QColor(Qt::white).rgba());
    16. QPainter painter(&image);
    17. QwtPlotRenderer renderer;
    18.  
    19. renderer.render(par->spectrum_plot, &painter, image.rect());
    20. painter.end();
    21. image.save(fileName, format.toLatin1(), setQuality);
    To copy to clipboard, switch view to plain text mode 

    This works so far as intended. Unfortunately, the problem concerning the too thin lines and odd looking texts are still there.
    Last edited by mariposa; 3rd October 2010 at 15:08.

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

    Default Re: Problems with QwtPlotRenderer from Qwt 6

    QwtPlotRenderer calculates and sets internally a scale factor depending on the ratio ( logicalDpi ) between plot and target paint device. While my code combines the scale factor assigned in the application code with this ratio, your code changes the ratio itsself. The effect on the internal scale factor is the same.

    Concerning the font I recommend to use a different one - mine looks much better. Concerning the lines you should try to assign non-cosmetic pens ( QPen::setCosmetic(bool) ), where you want to have them scaled like the fonts.

    For Qwt6.0.0 I will modify QwtPlotRenderer::renderDocument for images and introduce a flag so that the application can explicitely enable/disable the internal rounding of Qwt. Of course the "right" solution is to round to double values, that match the physical resolution of the target device, but I'm afraid it is too late for Qwt 6.0.0.

    Uwe

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

    mariposa (6th October 2010)

  5. #24
    Join Date
    Sep 2010
    Posts
    35
    Thanks
    5
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Problems with QwtPlotRenderer from Qwt 6

    Quote Originally Posted by Uwe View Post
    Concerning the lines you should try to assign non-cosmetic pens ( QPen::setCosmetic(bool) ), where you want to have them scaled like the fonts.
    I've tried to find an easy way to set the pen that is used for drawing the scales, but unfortunately I did not succeed. For the curve and grid it was quite easy (because of the setPen() member function), but I couldn't find something similar for the scales.

    Is there an "easy" way, or do I have to subclass QwtScaleDraw and reimplement the drawing functions?

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

    Default Re: Problems with QwtPlotRenderer from Qwt 6

    QwtScaleDraw explicitely disables cosmetic pens. So I'm afraid you have to overload QwtScaleDraw::drawTick and QwtScaleDraw::drawBackbone to set it again - but I'm not sure if you will see some alignment problems then.

    Uwe

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

    mariposa (6th October 2010)

Similar Threads

  1. Replies: 2
    Last Post: 23rd July 2010, 15:53
  2. problems
    By IRON_MAN in forum Newbie
    Replies: 11
    Last Post: 9th July 2009, 17:24
  3. problems going from 4.3.x to 4.4.0
    By Ovis in forum Installation and Deployment
    Replies: 4
    Last Post: 26th June 2008, 20:22
  4. Problems using a DLL
    By prosass in forum Newbie
    Replies: 7
    Last Post: 6th March 2007, 18:45
  5. QT4 Plugins - problems, problems
    By NormanDunbar in forum Qt Programming
    Replies: 6
    Last Post: 9th May 2006, 16:39

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