PDA

View Full Version : Stylesheets & printing



xburgerhout
16th October 2008, 15:50
Hi all,

I'm using the Qt4 stylesheets facility to apply a nice looking linear gradient to the background of my plot. This works great in the GUI, but when I print the plot, the stylesheet is ignored.

Is there an easy way to get this to work or do I need to patch the QwtPlot:: print() methods in Qwt itself?

Uwe
17th October 2008, 09:58
When you assign your gradient as background brush for the canvas, printing should paint your gradient too. ( Is there any good reason for using stylesheets for this ? )

If this is not possible do this:


virtual YourPlot::printCanvas(QPainter *painter,
const QRect &boundingRect, const QRect &canvasRect,
const QwtScaleMap maps[axisCnt],
const QwtPlotPrintFilter &filter)
{
// paint your gradient here
....

filter &= ~QwtPlotPrintFilter::PrintBackground;
QwtPlot::printCanvas(painter, ..., filter);
}

Uwe

xburgerhout
17th October 2008, 10:27
The stylesheet is mostly for convenience.

It allows me to store styles like:


#my_plot {
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop: 0 white, stop: 0.2 lightgrey, stop: 1 darkgray);
}

or


#my_plot {
background-color: lightsteelblue;
}


as a simple string in a configuration file.

I guess the easy way out is to change my config file format a bit and add the gradient code as you suggested.

Stylesheet support would be a nice feature to have though, you could then easily change the complete look of a plot simply by setting a new stylesheet.

Thanks,

Xander.

viridis
10th May 2010, 11:22
I want a gradient background in my plot and have implemented it like you suggested Uwe.
i.e. I set the gradient to the background brush of the canvas widget, and I've reimplemented printCanvas like this:



painter->save();
painter->setBrush(m_canvasBackground);
painter->drawRect(canvasRect);
painter->restore();

QwtPlotPrintFilter f;
f.setOptions(filter.options() & ~QwtPlotPrintFilter::PrintBackground);
QwtPlot::printCanvas(painter, boundingRect, canvasRect, maps, f);


Printing works as expected, however the plot in my application becomes black after this.
If I re-change the background brush of the canvas palette, all reworks again.

It looks like a bug in Qwt am I right?

Moreover, I'd like to know if reimplementing printCanvas is still the better solution? (qwt5.2)

And the last question: How can I control the print size, the with/height ratio...? I tried to change the paper size in the QPrintDialog but it doesn't work (which seems normal though..).

Thanks again for your great library!

Uwe
10th May 2010, 20:55
Printing works as expected, however the plot in my application becomes black after this.
I tried your code in the bode example on my Linux box with Qt 4.6.1 - but couldn't see this effect.


Moreover, I'd like to know if reimplementing printCanvas is still the better solution? (qwt5.2)
Well, it never was (my answer was about stylesheets only) - but it looks like Qwt 5.x doesn't print the gradient properly. I have not checked why, but Qwt 6.x from SVN trunk prints the gradient out of the box ( although the output is quite heavy for high resolution prints ).


And the last question: How can I control the print size, the with/height ratio...?

void QwtPlot::print(QPainter *, const QRect &, ... ) const;

Uwe