Search code examples
pythonplotsavepyqtpyqtgraph

PyQtGraph - Open 'file save dialog' using button instead of through context menu


In pyqtgraph there is option to save plot as image/csv/svg/etc. just by clicking right mouse button on the plot and choosing 'Export.." option. There is also possibility to export plot like this: (assuming pw is my plot)

ex1 = pg.exporters.CSVExporter(pw.plotItem)
ex1.export('test.csv')
ex2 = pg.exporters.SVGExporter(pw.plotItem)
ex2.export('test.svg')
ex3 = pg.exporters.ImageExporter(pw.plotItem)
ex3.export('test.img')

The problem is that I don't want to use right-click menu (and so on) neither to directly save plot in fixed format and to predefined path. I want a function that when called will open up this same 'save file dialog' that hides under 'Export..' menu option. I will then connect it to a button or whatever and voilà :)

Any ideas?


Solution

  • I needed to do this and and this is how I did it.

    from pyqtgraph.GraphicsScene import exportDialog
    exportDialog = exportDialog.ExportDialog(pw.plotItem.scene())
    exportDialog.show(pw.plotItem)
    

    This creates an Export dialog that targets the GraphicsScene holding the plotItem.