Rendering QGraphicsItem without QGraphicsScene
-
Hi!
I've got gantt chart build as QGraphicsItem without any painting operation, but with bunch of children. I need to export it to some image file, preferably SVG. It's easy when it is displayed in QGraphicsView by QGraphicsScene (it's the only one item added to scene):
@
QSvgGenerator svgGen;
svgGen.setFileName(filename);
QRectF r = m_scene->sceneRect();
qDebug() << "image size:" << r << r.size().toSize();
svgGen.setSize(r.size().toSize());
svgGen.setViewBox(r);
svgGen.setTitle(tr("Gantt chart"));
svgGen.setDescription(tr("Gantt chart"));
QPainter painter;
painter.begin(&svgGen);
m_scene->render(&painter);
painter.end();
@But is there an (easy) way to perform such rendering without QGraphicsScene - i.e. inside of GanttChart class (descendant from QGraphicsItem) ?
-
You can ask for an element to draw itself "QGraphicsItem::paint(QPainter * painter, ...) ":http://qt-project.org/doc/qt-5/qgraphicsitem.html#paint
-
[quote author="Konstantin Podsvirov" date="1394535826"]You can ask for an element to draw itself "QGraphicsItem::paint(QPainter * painter, ...) ":http://qt-project.org/doc/qt-5/qgraphicsitem.html#paint[/quote]
Continuing.. something like the following:
QImage image(size_x, size_y, format);
QPainter painter(&image);QStyleOptionGraphicsItem opt;
item->paint(&painter, &opt);