Results 1 to 6 of 6

Thread: Saving the entire .ui form as an Image file from QTcreator

  1. #1
    Join Date
    Nov 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Red face Saving the entire .ui form as an Image file from QTcreator

    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.

    Capture.jpg

    Thanks.

    Qt version- 5.7

    PS: PFA an image of the view.
    Last edited by das.joyita; 5th December 2016 at 15:59.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Saving the entire .ui form as an Image file from QTcreator

    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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

  3. #3
    Join Date
    Nov 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Saving the entire .ui form as an Image file from QTcreator

    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.
    Capture.jpg This has to look like this one after distortion -> cylinder-f.jpg

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

    Qt Code:
    1. QWidget *widget= ui->mywidget;
    2.  
    3. QPixmap pic = QPixmap::grabWidget(widget);
    4. widget->render(&pic);
    5. pic.save("testScreen.png");
    To copy to clipboard, switch view to plain text mode 

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

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Saving the entire .ui form as an Image file from QTcreator

    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,
    _

  5. #5
    Join Date
    Nov 2016
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Saving the entire .ui form as an Image file from QTcreator

    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

  6. #6
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Saving the entire .ui form as an Image file from QTcreator

    By the way, QPixmap::grabWidget() is an obsolete method. 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.
    <=== The Great Pumpkin says ===>
    Please use CODE tags when posting source code so it is more readable. Click "Go Advanced" and then the "#" icon to insert the tags. Paste your code between them.

Similar Threads

  1. Displaying file name (not the entire file name path)
    By Ferric in forum Qt Programming
    Replies: 2
    Last Post: 15th November 2011, 05:23
  2. QCryptographicHash an entire file
    By pyramation in forum Qt Programming
    Replies: 2
    Last Post: 4th November 2010, 00:41
  3. Replies: 2
    Last Post: 22nd August 2009, 00:09
  4. Saving pure plot data to image file
    By Debilski in forum Qwt
    Replies: 4
    Last Post: 7th April 2009, 18:02
  5. Accessing the entire file..
    By Kapil in forum Newbie
    Replies: 1
    Last Post: 28th April 2006, 08:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.