Results 1 to 6 of 6

Thread: How do I get a snapshot of a widget ?

  1. #1
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default How do I get a snapshot of a widget ?

    I'm using PySide2, to create a node graph based widget, which is set inside a scrollarea.

    I would like to save a snapshot of all the nodes inside my scrollarea. Currently I have to take a screenshot, scroll, and take another, and another, then I have to use photoshop to stitch them together. (basically pan and use snipping tool and stitch to make a image with all my nodes.)

    I found this on Stack,
    Qt Code:
    1. .grabWidget() & .grab()
    To copy to clipboard, switch view to plain text mode 
    but it says in the Qt docs that it has been discontinued. If i implement it anyway, it crashes my program.

    Qt Code:
    1. QtGui.QPixmap.grabWidget(widget)
    To copy to clipboard, switch view to plain text mode 

    https://stackoverflow.com/questions/...include-the-ti



    Is there another way to create a snapshot?
    Attached Images Attached Images
    • File Type: jpg 2.jpg (23.3 KB, 4 views)

  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: How do I get a snapshot of a widget ?

    Create a QImage then pass it to the QWidget::render() method.
    <=== 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
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I get a snapshot of a widget ?

    Thanks for your reply, d_stranz.

    So, I'm get False when I run my code. What did I miss?

    Qt Code:
    1. file = QtCore.QFile("E:/Junk/myFile.png")
    2. file.open(QtCore.QIODevice.WriteOnly)
    3.  
    4. myWidget = getActiveWidget() # just returns the widget
    5.  
    6. pix = QtWidgets.QImage()
    7.  
    8. myWidget.render(pix)
    9.  
    10. pix.save(file)
    To copy to clipboard, switch view to plain text mode 


    Thanks!

  4. #4
    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: How do I get a snapshot of a widget ?

    You probably need to create the QImage with the correct size and format before you can render to it.
    <=== 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.

  5. #5
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I get a snapshot of a widget ?

    Quote Originally Posted by d_stranz View Post
    You probably need to create the QImage with the correct size and format before you can render to it.
    Yup! That was it. Thank you.
    Qt Code:
    1. pix= QtWidgets.QImage(wid.size(),QtWidgets.QImage.Format.Format_ARGB32)
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2016
    Location
    Venice, California
    Posts
    87
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How do I get a snapshot of a widget ?

    Turns out the widget was a QGLWidget.

    I came across another issue that I'd hoping to get help with. I used .grabFrameBuffer() and was successful in getting the widget to save. The issue I have now is it's only saves what is visible- the items cutoff by the widget is not rendered to file.
    It does show all the nodes in the little preview on the bottom right corner, even though its beyond the QGLWidget , so it does know it exists.

    Is there a way to render everything that is on the widget, and not just what is visible ?

    Thanks,

    Nick

Similar Threads

  1. How to get a snapshot of a video in Qt???
    By wshn13 in forum Qt Programming
    Replies: 12
    Last Post: 1st August 2011, 08:22
  2. Getting the lates snapshot of qt
    By Lykurg in forum Installation and Deployment
    Replies: 15
    Last Post: 10th April 2009, 22:38
  3. Where can I get snapshot for Qt 4.3.0
    By davit in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 09:17
  4. Build a snapshot
    By Dark_Tower in forum Installation and Deployment
    Replies: 1
    Last Post: 23rd April 2006, 17:00
  5. Qt 4.1.1 snapshot on windows
    By ldindon in forum Installation and Deployment
    Replies: 4
    Last Post: 13th February 2006, 14:58

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.