Qt programming

Creating a SVG based image for QTextDocument

What I needed was a way to create an image from SVG raw data generated in the fly. Here is possible solution:

<sxh c++>

QTextCursor mainCursor;  // Should be initialised somehow
QString figData(
  "<svg xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\"> "
  "<circle cx=\"100\" cy=\"50\" r=\"40\" stroke=\"black\" "
  "stroke-width=\"2\" fill=\"red\"/> "
  "</svg>");
 QXmlStreamReader figReader(figData);
 QSvgRenderer renderer;
 bool status = renderer.load(&figReader);
 if (!status) {
    std::cerr << "CANNOT LOAD IMAGE\n";
 }
 QImage image = QImage(QSize(100,100),QImage::Format_RGB32);
 QPainter painter(&image);
 renderer.render(&painter);
 painter.end();
 mainCursor.insertImage(image);

</sxh>

Property browser framework

  • QdbtTabular The QdbtTabular class represents a table widget which looks similar to the `detailed list' of Windows 95.
  • en/research/notebook/qt.txt
  • Last modified: 2017/10/02 15:54
  • (external edit)