How to print/screenshot a tabwidget to an image file (.jpg/.png) in high resolution?
Piyush last edited by Piyush
I am working on a piece of code wherein I have to print the tabwidget to an image file (.png/.jpg) file. The file is being created by the following code but i cannot view it.
``` printer.PrinterMode(QtPrintSupport.QPrinter.HighResolution) printer.setOrientation(QtPrintSupport.QPrinter.Landscape) printer.setPaperSize(QtCore.QSizeF(297, 420), QtPrintSupport.QPrinter.Millimeter) temp_pdf = "abc.png" printer.setOutputFileName(temp_pdf) painter = QtGui.QPainter(printer) painter.drawPixmap(0, 10, self.ui.tabWidget.grab()) painter.end()
Do you want to send the picture to a printer or why do you use QPrinter instead QPixmap::save()?
I was actually working with PDF before this after which the requirement changed to image file. I am open to using QPixmap but I don't know how? Could you please help me with an example?
tried Qpixmap.grabwidget but it seems to be deprecated in PyQt5.
@mrjj Can you share an example?
There is not so much to say about it.
// make bitmap that is size of widget QPixmap pixmap(widget->size()); // ask widget to paint it self to the pixmap widget->render(&pixmap);
@mrjj Thanks. It worked. Was a very simple and quick solution.
pixmap = QtGui.QPixmap(self.ui.tab_2.size()) self.ui.tab_2.render(pixmap) pixmap.save('abc.jpg','jpg')