I wasn't able to get grab() to work. I received an error that QMainWindow 
does not have a grab method. However, render() did the trick. Thanks for 
pointing that out! Here's the code I used, in case anyone else comes across 
this.

pixmap = QtGui.QPixmap(win.size())
win.render(pixmap)
pixmap.save("plot.png")


This appears to give me an exact image of what I saw in the window.


On Thursday, June 18, 2020 at 10:14:08 PM UTC-7, Kenneth Lyons wrote:
>
> One option I can think of is that QWidget (hence QMainWindow) has a grab() 
> <https://doc.qt.io/qt-5/qwidget.html#grab> method render to a pixmap 
> which can then be saved to a file, so you could use that to generate a 
> "screenshot" of the whole window. Does this do what you're after?
>
> pixmap = win.grab()
> pixmap.save("plot.png")
>
> (in place of imv.export("plot.png"))
>
> It doesn't offer much in terms of options like DPI (you could blow it up 
> by specifying a large window size, but the axis labels won't scale with 
> it). There may be more flexibility with render() 
> <https://doc.qt.io/qt-5/qwidget.html#render-1>, I haven't tried it.
>
> On Wednesday, June 17, 2020 at 3:35:47 PM UTC-7, Matt Huszagh wrote:
>>
>> I'm attempting to export the contents of a full window or layout. The 
>> layout consists of a central ImageView with x and y axes. I'm able to 
>> export the image but then it ignores the axes and y inversion. For 
>> instance, something like this will export the central image.
>>
>> ```
>> from pyqtgraph.Qt import QtGui
>> import pyqtgraph as pg
>> import pyqtgraph.exporters
>> import numpy as np
>>
>> app = QtGui.QApplication([])
>> win = QtGui.QMainWindow()
>> imv = pg.ImageView(view=pg.PlotItem())
>> img_view = imv.getView()
>> img_view.invertY(False)
>> img_view.setLimits(yMin=0, yMax=512)
>> img_view.getAxis("left").setScale(0.5)
>> win.setCentralWidget(imv)
>> win.show()
>> win.setWindowTitle("Range Plot")
>> imv.setPredefinedGradient("flame")
>> imv.setImage(np.zeros((2000, 513)), xvals=[i for i in range(2000)])
>> imv.setLevels(0, 100)
>> app.processEvents()
>> imv.export("plot.png")
>> ```
>>
>> How can I get this to export the full window as an image (preserving 
>> axes, aspect ratios, y-inversion, etc.)? Is there some window class or 
>> layout on which I can call `scene()`? Thanks.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"pyqtgraph" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/pyqtgraph/b2c896a2-aed5-45bd-9f6d-dd003b0067e6o%40googlegroups.com.

Reply via email to