August 29, 2011

bunjee bunjee
Lab Rat
120 posts

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.

5 replies

August 29, 2011

peppe peppe
Ant Farmer
1025 posts

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

 Signature 

Software Engineer
KDAB (UK) Ltd., a KDAB Group company

August 29, 2011

marcoB marcoB
Ant Farmer
167 posts

I just gone out of this :)
Here the code I used:

  1. QImage image(item->boundingRect().size().toSize(), QImage::Format_RGB32);
  2. image.fill(QColor(0, 0, 0).rgb());
  3. QPainter painter(&image);
  4. qobject_cast<QGraphicsObject*>(item)->paint(&painter, &styleOption);
  5. painter.end();

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

August 29, 2011

bunjee bunjee
Lab Rat
120 posts

Thanks guys !

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

August 29, 2011

bunjee bunjee
Lab Rat
120 posts

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

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

B.A.

August 29, 2011

marcoB marcoB
Ant Farmer
167 posts

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 :)

@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 :)

 
  ‹‹ How can I use QSqlRelationalTableModel to read-write the result set from a query?      QTableWidget and QComboBox, issues when changing the QComboBox content ››

You must log in to post a reply. Not a member yet? Register here!