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;
    QRectF r = m_scene->sceneRect();
    qDebug() << "image size:" << r << r.size().toSize();
    svgGen.setTitle(tr("Gantt chart"));
    svgGen.setDescription(tr("Gantt chart"));
    QPainter painter;

    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, ...) ":

  • [quote author="Konstantin Podsvirov" date="1394535826"]You can ask for an element to draw itself "QGraphicsItem::paint(QPainter * painter, ...) ":[/quote]

    Continuing.. something like the following:

    QImage image(size_x, size_y, format);
    QPainter painter(&image);

    QStyleOptionGraphicsItem opt;
    item->paint(&painter, &opt);

Log in to reply

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