Results 1 to 5 of 5

Thread: chart saving

  1. #1
    Join Date
    May 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default chart saving

    Hello,

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

    Qt Code:
    1. def saveChart(self):
    2. fileName = QtGui.QFileDialog.getSaveFileName(self, 'Export File Name', 'JPGgraph', 'JPG Documents (*.jpg)')
    3. if not fileName.isEmpty():
    4. if not fileName.toLower().endsWith('.jpg'):
    5. fileName += '.jpg'
    6. currentPlot = self.plots[self.graphComboBox.currentIndex()].plot
    7. filtre = QwtPlotPrintFilter()
    8. screen = QtGui.QPixmap.grabWidget(currentPlot)
    9. #screen.fill(QtCore.Qt.white)
    10. #print currentPlot.size()
    11. #print currentPlot.rect()
    12. #print currentPlot.sizeHint()
    13. #print currentPlot.minimumSizeHint()
    14. currentPlot.print_(screen, filtre)
    15. screen.save(fileName, "JPG", -1)
    To copy to clipboard, switch view to plain text mode 

    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 :

    Or :


    Someone know what I should do to solve this issue ?

    Thanks in advance,

    Cédric

  2. #2
    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: chart saving

    I'm not sure what you want to do, but at least the grabWidget call is completely nonsense in the code above.

    Uwe

  3. #3

    Default Re: chart saving

    Hi,

    try a more simply solution :

    Qt Code:
    1. QString fileName = "sauve.jpg";
    2. fileName = QFileDialog::getSaveFileName(this,"Sauve...","..."," (*.jpg)");
    3. if(!fileName.isEmpty())
    4. {
    5. QPixmap picture;
    6. picture = QPixmap::grabWidget(currentplot);
    7. picture.save(fileName);
    8. }
    To copy to clipboard, switch view to plain text mode 

    I think you needn't filter

  4. #4
    Join Date
    May 2011
    Posts
    4
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: chart saving

    This works, the problem is solved.
    Thanks you very much !

  5. #5
    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: chart saving

    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

Similar Threads

  1. Chart and diagrams for Qt
    By bred in forum Qt Programming
    Replies: 4
    Last Post: 3rd January 2011, 21:10
  2. kd chart question
    By yunpeng880 in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2009, 02:43
  3. how much about kd chart
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 12th March 2009, 10:54
  4. what chart for qt?
    By yunpeng880 in forum Qt Programming
    Replies: 1
    Last Post: 8th January 2009, 12:07

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.