Results 1 to 5 of 5

Thread: Extract QImage from QQuickItem

  1. #1
    Join Date
    Mar 2010
    Posts
    10
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Extract QImage from QQuickItem

    Hi,

    I would like to process an image loaded into a Flickable QML element in C++ land but I am failing to obtain the original image. So far I'm only seem able to obtain an image of the QQuickWindow
    and would liek to know if there is a way to obtain the whole loaded image.

    I am calling a Q_INVOKABLE method of a C++ object as follows:


    Qt Code:
    1. Flickable {
    2. id: content
    3. clip: false
    4. anchors.fill: parent
    5. boundsBehavior: Flickable.StopAtBounds
    6.  
    7. Loader {
    8. id: contentLoader
    9. anchors.centerIn: parent
    10. }
    11.  
    12. MouseArea {
    13. anchors.fill: parent
    14. onClicked: {
    15. console.log("[veo] onClicked - capture triggered")
    16. cplusplusobject.process(contentLoader.item) <----------------- call to C++
    17. }
    18. }
    To copy to clipboard, switch view to plain text mode 


    In C++ I have:

    Qt Code:
    1. void
    2. Cplusplusobject::process(const QVariant &v)
    3. {
    4. qDebug() << "[veo]" << __FUNCTION__;
    5. QQuickItem *item = qobject_cast<QQuickItem *>( v.value<QObject*>() );
    6. qDebug() << "Item dimensions:" << item->width() << item->height();
    7.  
    8. item->dumpObjectInfo();
    9.  
    10. QQuickWindow *window = item->window();
    11. QImage image = window->grabWindow();
    12. ...
    To copy to clipboard, switch view to plain text mode 

    The printed item dimensions do correspond to the original image but I fail to see how to turn the QQuickItem into a QImage.

    Any suggestions please?

  2. #2
    Join Date
    Dec 2013
    Posts
    2
    Thanks
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Extract QImage from QQuickItem

    Up
    I'm also interested by an answer.

    I would like to store an child QML item to an image.
    Currently, I use the grabWindow() method. It works, but this isn't what I want. This stores the whole window.

    I saw this method, which looks right:
    http://stackoverflow.com/questions/1...ving-qml-image
    But QtDeclarativeItem is obsolete, and QQuickItem hasn't got a Paint() method.
    I tried to use the QQuickPaintedItem class, which has got a paint() method, but it is virtual. I don't know how to use it in my case (I'm a newbie).

  3. #3
    Join Date
    Jan 2013
    Posts
    2
    Qt products
    Qt4 Qt5 Qt Jambi
    Platforms
    Unix/X11 Windows Android

    Default Re: Extract QImage from QQuickItem

    I am also interested in that. Does anyone get it?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Extract QImage from QQuickItem

    In Qt Quick items are OpenGL primitives. If you want to get them as images, you have to force the item to be rendered on a texture, e.g. using ShaderEffectSource and then use QQuickItem API to identify the texture so that you can download it from the atlas. That is not something straightforward though.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    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: Extract QImage from QQuickItem

    If the item is fully visible, you could grab a screenshot of the window (QWindow::grabWindow()) and the copy the area of the item into the target image.

    Cheers,
    _

Similar Threads

  1. Extract/Use another exe's icon
    By aguayro in forum Qt Programming
    Replies: 2
    Last Post: 30th April 2012, 14:56
  2. Can you extract a tarball with Qt?
    By jshafferman in forum Qt Programming
    Replies: 1
    Last Post: 8th December 2010, 23:26
  3. Qt extract from xml with DOM
    By Leoha_Zveri in forum Qt Programming
    Replies: 0
    Last Post: 4th October 2009, 10:59
  4. How To Extract A File
    By deekayt in forum General Programming
    Replies: 7
    Last Post: 5th December 2006, 18:27
  5. Replies: 3
    Last Post: 15th March 2006, 11:44

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.