I'm trying to use Python to programmatically save a QWidget in PyQt4 as an image (any format would be fine - PNG, PDF, JPEF, GIF...etc)
I thought this would be very straightforward, but I actually wasn't able to find anything on the web about it. Can someone point me in the right direction?
To be clear, I'm trying to do this
gui = <SOME QMainWindow>
gui.show() # this displays the gui. it's useful, but what i need is to save the image
gui.save("image.png") ## How do I do this?
You can do this using the
QPixmap.grabWindow()
method.From the docs:
Sample code:
This will produce a window that looks like this:
When you click the button, it will create a file named
Screenshot.jpg
in the current directory. Said image will look like this (notice the window frame is missing):