Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Rendering QGraphicsItem without QGraphicsScene
Qt 6.11 is out! See what's new in the release blog

Rendering QGraphicsItem without QGraphicsScene

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 2.8k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    konserw
    wrote on last edited by
    #1

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

    1 Reply Last reply
    0
    • podsvirovP Offline
      podsvirovP Offline
      podsvirov
      wrote on last edited by
      #2

      You can ask for an element to draw itself "QGraphicsItem::paint(QPainter * painter, ...) ":http://qt-project.org/doc/qt-5/qgraphicsitem.html#paint

      1 Reply Last reply
      0
      • I Offline
        I Offline
        immersive_dev
        wrote on last edited by
        #3

        [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);

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved