Re: Problems with QwtPlotRenderer from Qwt 6
Quote:
Originally Posted by
mariposa
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.
Quote:
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.
Quote:
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.
Code:
{
if ( painter && painter->transform().isScaling() )
return false;
...
}
Uwe
PS: Forget about trying to find your code for Qwt5 - you won't succeed. Better try to support the development of Qwt 6
1 Attachment(s)
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:
Attachment 5264
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:
Code:
const double toInch = 1.0 / 25.4; //convert mm to inch
//the user is asked for setWidth and setHeight (intended "real world" size in mm)
const QSizeF size
= QSizeF(setWidth, setHeight
) * toInch
* setResolution;
const QRectF documentRect
( 0.0,
0.0, size.
width(), size.
height() );
const qreal toDPM = 1.0 / 0.0254;
const QRect imageRect
= documentRect.
toRect();
//the selected resolution (setResolution) is converted to DotsPerMeter
image.setDotsPerMeterX(setResolution * toDPM);
image.setDotsPerMeterY(setResolution * toDPM);
image.
fill(QColor(Qt
::white).
rgba());
QwtPlotRenderer renderer;
renderer.render(par->spectrum_plot, &painter, image.rect());
painter.end();
image.save(fileName, format.toLatin1(), setQuality);
This works so far as intended. Unfortunately, the problem concerning the too thin lines and odd looking texts are still there.
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
Re: Problems with QwtPlotRenderer from Qwt 6
Quote:
Originally Posted by
Uwe
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?
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