How to break QGraphicsScene into fragments?



  • Hi!
    I'm downloading QGraphicsScene from .SVG file.
    How to break QGraphicsScene into fragments?

    And is it possible to save QGraphicsScene fragmentally without linking into a single fragment? I keep so:

            QString newPath = QFileDialog::getSaveFileName(this, trUtf8("Save SVG"),
                path, tr("SVG files (*.svg)"));
    
            if (newPath.isEmpty())
                return;
    
            path = newPath;
    
            QSvgGenerator generator;        
            generator.setFileName(path);   
            generator.setSize(QSize(scene->width(), scene->height()));  
            generator.setViewBox(QRect(0, 0, scene->width(), scene->height())); 
            generator.setTitle(trUtf8("SVG Example"));                        
            generator.setDescription(trUtf8("File created by SVG Example"));    
    
            QPainter painter;
            painter.begin(&generator);  
            scene->render(&painter);   
            painter.end(); 
    

    I lood so:

    void Paint::on_loadButton_clicked() //load scene
    {
        QString newPath = QFileDialog::getOpenFileName(this, trUtf8("Open SVG"),
                                                       path, tr("SVG files (*.svg)"));
    
        if (newPath.isEmpty())
                return;
    
            path = newPath;
            scene->clear();
    
            //QSvgRenderer myRenderer;
            QSvgRenderer* myRenderer = new QSvgRenderer();
            myRenderer->load(path);
            //scene->setSceneRect(myRenderer->viewBoxF());
            QGraphicsSvgItem *myItem = new QGraphicsSvgItem();
            myItem->setSharedRenderer(myRenderer);
            scene->addItem(myItem);
    }
    

  • Lifetime Qt Champion

    Hi,

    What do you mean by fragments ?



  • After saving to SVG, all elements drawn separately are combined into one element. If you open SVG the Coreldraw, you can also see that all the individual elements are grouped into one large element.



  • In CorelDRAW calls to cancel the grouping.


  • Lifetime Qt Champion

    Then you'll have to implement that yourself. The render method won't do that for you.



  • Is it possible to save in SVG so that all fragments are not combined into one?


  • Lifetime Qt Champion

    Quoting myself:
    @SGaist said in How to break QGraphicsScene into fragments?:

    Then you'll have to implement that yourself. The render method won't do that for you.


Log in to reply