[Interest] how render a qgraphicsscene to svg and paste it to the clipboard

helferthomas at free.fr helferthomas at free.fr
Sat Sep 14 08:12:20 CEST 2013


Hi,

I am using the qgraphicsview/qgraphicscene framework. I am able to write file from the drawn scene to multiple file formats, including svg using QtSvg. I want to be able to copy the scene to the clipboard. For a bitmap copy, i am using the following code:

       // Selections would also render to the file
      this->scene->clearSelection();
      // Create the image with the exact size of the shrunk scene
      QImage image(scene->sceneRect().size().toSize(), QImage::Format_ARGB32);
      image.fill(Qt::transparent);
      QPainter painter;
      painter.begin(&image);
      painter.setRenderHint(QPainter::Antialiasing);
      this->scene->render(&painter);
      painter.end();
      QApplication::clipboard()->setImage(image,QClipboard::Clipboard);

which works great. However I wonder if I can do copy the scene as svg data to the clipboard. Does anybody know how to do it ?

Thanks for any help.

Helfer Thomas



More information about the Interest mailing list