QGraphicsItem screenshot



  • Greetings Qt Dev Network,

    Is it possible to take a screenshot of a specific QGraphicsItem (Not an area of QGraphicsScene but the QGraphicsItem itself) ?

    Has anyone got a straightforward implementation of this ?

    Thanks guys.

    B.A.



  • Create a QImage/QPixmap of the item's boundingRect(), create a QPainter on that and then call item->paint()?



  • I just gone out of this :)
    Here the code I used:
    @
    QImage image(item->boundingRect().size().toSize(), QImage::Format_RGB32);
    image.fill(QColor(0, 0, 0).rgb());
    QPainter painter(&image);
    QStyleOptionGraphicsItem styleOption;
    qobject_cast<QGraphicsObject*>(item)->paint(&painter, &styleOption);
    painter.end();@

    here my "item" is a QDeclarativeitem, but its inerithed by QGraphicsItem, so souldn't be any problem I think.



  • Thanks guys !

    It looks easier than I thought. I wonder if item transformations can screw up the painting.



  • @deimos: your mediadownloader is a nice piece of software !

    Are you playing the videos natively using FFMPEG and QPixmap(s) ?

    B.A.



  • bq. I wonder if item transformations can screw up the painting.

    whit that code the image grabbed will be the item without transformations. But if you inscribe your item into another, you can then grab the outer one with the inner rotated :)

    bq. @deimos: your mediadownloader is a nice piece of software !
    Are you playing the videos natively using FFMPEG and QPixmap(s) ?

    thanks a lot. Compliments are always welcome and I didn't received a lot even if it is been downloaded a lot :)
    Video are played with phonon (I am rewriting it using QtMultimediaKit without phonon) and since youtube needs cookies and with phonon you have not direct access to network (you can't set QNetworkRequest) I have subclassed QIODevice to threat streaming videos as a local file. They can be played also with mplayer. FFMPEG is used only to convert them.

    sorry to all for this OT

    @bunjee: if you want to find me I am in #qt, #meego channels at freenode irc :)


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.