PDA

View Full Version : Saving the entire .ui form as an Image file from QTcreator



das.joyita
5th December 2016, 10:30
Hi,

I am trying to save the entire 'MainWindow.ui' form, of my QT widget Application, as an Image (.jpg or .png) file in my system. The view/form has Mainwindow--> Central widget--> which contains multiple frame with grid layout and multiple QGraphicsView. I am trying to save the form in Qt designer from Qt creator.

My requirement is to save entire view as an image file in my system. Please tell me how do i save the entire form as an image file.

12238

Thanks.

Qt version- 5.7

PS: PFA an image of the view.

d_stranz
5th December 2016, 16:57
My requirement is to save entire view as an image file in my system. Please tell me how do i save the entire form as an image file.

Do you need to do this once, or do you need to do it at anytime while your program is running?

If you need to do it once, then use Qt Designer's tool to view your form (sorry, I don't remember the command) and use Windows Snipping Tool or some other software to make a screen shot.

If you need to do it at any time while the program is running, then use the QWidget::render() to paint into a QPixmap, then QPixmap::save() to save it to your file.

das.joyita
6th December 2016, 10:55
Thanks for your reply. I have to do it each time the program is running. Then distort the Image using image magick and load it again to the view.
12240 This has to look like this one after distortion -> 12241

Below is my code for saving but i dont see it in my project folder. Please let me know what is going wrong.



QWidget *widget= ui->mywidget;

QPixmap pic = QPixmap::grabWidget(widget);
widget->render(&pic);
pic.save("testScreen.png");


my widget is the container containing all the frames, graphicviews and labels.

anda_skoa
6th December 2016, 13:48
If you don't specify a path then the file will be written to the application's working directory.

Are you launching your application with the "project folder" as its working directory?

Cheers,
_

das.joyita
6th December 2016, 14:50
Yes doing it from the directory. I gave the full path and it solved my issue.

Thanks so much! And gosh i can be dumb :P

d_stranz
6th December 2016, 17:11
By the way, QPixmap::grabWidget() is an obsolete method (http://doc.qt.io/qt-5/qpixmap-obsolete.html). QWidget::render() does the same thing, and in fact in your code posted above, you're really capturing the pixmap twice - once in line 3, then again in line 4. Get rid of line 3 and your code will work in Qt5.