PDA

View Full Version : chart saving



cedrix
5th May 2011, 20:23
Hello,

I am using PyQwt, and I have some issues for saving charts.
Here is my code :


def saveChart(self):
fileName = QtGui.QFileDialog.getSaveFileName(self, 'Export File Name', 'JPGgraph', 'JPG Documents (*.jpg)')
if not fileName.isEmpty():
if not fileName.toLower().endsWith('.jpg'):
fileName += '.jpg'
currentPlot = self.plots[self.graphComboBox.currentIndex()].plot
filtre = QwtPlotPrintFilter()
screen = QtGui.QPixmap.grabWidget(currentPlot)
#screen.fill(QtCore.Qt.white)
#print currentPlot.size()
#print currentPlot.rect()
#print currentPlot.sizeHint()
#print currentPlot.minimumSizeHint()
currentPlot.print_(screen, filtre)
screen.save(fileName, "JPG", -1)

I have several QwtPlot in a QStackWidget, which is in a QHorizontalLayout, which is in a QWidget which is the central widget of my QMainWindow.

When I try to save on of my chart, either the width is higher than the height or the height is higher than the width.
The result is :
http://i55.tinypic.com/1zbdo2s.jpg
Or :
http://i53.tinypic.com/b6eb2e.jpg

Someone know what I should do to solve this issue ?

Thanks in advance,

Cédric

Uwe
6th May 2011, 06:52
I'm not sure what you want to do, but at least the grabWidget call is completely nonsense in the code above.

Uwe

didji31
6th May 2011, 08:44
Hi,

try a more simply solution :



QString fileName = "sauve.jpg";
fileName = QFileDialog::getSaveFileName(this,"Sauve...","..."," (*.jpg)");
if(!fileName.isEmpty())
{
QPixmap picture;
picture = QPixmap::grabWidget(currentplot);
picture.save(fileName);
}

I think you needn't filter

cedrix
6th May 2011, 09:19
This works, the problem is solved.
Thanks you very much !

Uwe
6th May 2011, 09:49
Probably this is not what you want: better try to understand the difference between QPixmap::grabWidget and QwtPlot::print before you decide.


With QwtPlot::print you render a plot into a given rectangle. This means the current size of the plot widget doesn't matter and you can create individual layouts f.e with several plots on the same page.

Only with QwtPlot::print you can create scalable vector formats like SVG and PDF.

Only with QwtPlot::print you can manipulate the rendering of the plot. F.e. when printing to a printer without colors you don't want to waste toner for the background of the plot canvas that make the curves hard to see.

Note that Qwt 6 ( I know there are no Python bindings yet ) has a double based render engine what is of major importance for scalable vector graphics - f.e. when you zoom in/out in your PDF viewer ! .

Uwe