Writing QGraphicsItemGroup to a .png file?



  • Is it possible to write a QGraphicsItemGroup (or the contents of a QGraphicsItemGroup) to an image file, specifically a .png? If it is, I'm not sure how to go about doing it.



  • Maybe something like that :)

    @
    QImage img(item->boundingRect().size().toSize(), QImage::Format_RGB32);
    img.fill(QColor(255, 255, 255).rgb());
    QPainter painter(&img;);
    QStyleOptionGraphicsItem styleOption;
    item->paint(&painter;, &styleOption;);
    img.save(path);
    @

    where "item" is your QGraphicsItemGroup.

    P.S. I'm not sure, but you can try..



  • [quote author="kibsoft" date="1311145041"]Maybe something like that :)

    @
    QImage img(item->boundingRect().size().toSize(), QImage::Format_RGB32);
    img.fill(QColor(255, 255, 255).rgb());
    QPainter painter(&img;);
    QStyleOptionGraphicsItem styleOption;
    item->paint(&painter;, &styleOption;);
    img.save(path);
    @

    where "item" is your QGraphicsItemGroup.

    P.S. I'm not sure, but you can try..[/quote]

    I tried doing that, but it doesn't work; it only returns a blank image that's the same dimension of the QGraphicsItemGroup.


Log in to reply
 

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