Important: Please read the Qt Code of Conduct -

Getting a snapshot of a QDeclarativeItem/QGraphicsVideoItem (OpenGL?)

  • I have a QML application which uses a QDeclarativeItem, pulled in from a C++ plugin. This item has a QGraphicsVideoItem as a child, filling its entirety. I would like to capture a QPixmap or QImage of the contents of either of these items (since they should be identical as displayed on the screen). I've tried many variations of the following code:

    @#ifdef TRY_SCENE_RENDER
    QSize useSize = scene()->size().toSize();
    QSize useSize = boundingRect().size().toSize();

    #ifdef TRY_QIMAGE
    QImage image(useSize, QImage::Format_RGB32);
    QPixmap image(useSize);

    QPainter painter(&image);

    paint(&painter, 0, 0); // I have tried passing in a QStyleOptionGraphicsItem with exposedRect set to boundingRect()

    With paint(), I am left with either an all-green or all-black image; with scene()->render(), the other items in the scene are rendered correctly, but the QGraphicsVideoItem is blank.

    This is on MeeGo, which I believe always uses "-graphicssystem opengl" - at the very least, if I start a test app without those switches then the QGraphicsVideoItem is not displayed.

    I suspect that my problem has something to do with the OpenGL backend, but I'm at a loss. Does anyone have any ideas here? TIA...

  • Did you try to use "QPixmap::grabWindow": ?

Log in to reply