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. How to use QSvgRenderer load .svg in scene QGraphicsScene ?

How to use QSvgRenderer load .svg in scene QGraphicsScene ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 1.0k 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.
  • M Offline
    M Offline
    Mikeeeeee
    wrote on last edited by Mikeeeeee
    #1

    Hi!
    I save a QGraphicsScene to an svg file.
    How to use QSvgRenderer load .svg in scene QGraphicsScene ?
    If I do so, I get a white screen

        QString newPath = QFileDialog::getOpenFileName(this, trUtf8("Open SVG"),
                                                       path, tr("SVG files (*.svg)"));
    
        if (newPath.isEmpty())
                return;
    
            path = newPath;
            scene->clear();
    
            QSvgRenderer w;
            w.load(path);
            scene->setSceneRect(w.viewBoxF());
    
    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What about using QGraphicsSvgItem ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • M Offline
        M Offline
        Mikeeeeee
        wrote on last edited by
        #3

        I did so, but how to set my scene the myItem?

            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);
                
        
        jsulmJ 1 Reply Last reply
        0
        • M Mikeeeeee

          I did so, but how to set my scene the myItem?

              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);
                  
          
          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Mikeeeeee said in How to use QSvgRenderer load .svg in scene QGraphicsScene ?:

          I did so, but how to set my scene the myItem?

          Please read documentation: https://doc.qt.io/qt-5/qgraphicsscene.html#addItem

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          1
          • M Offline
            M Offline
            Mikeeeeee
            wrote on last edited by
            #5

            Thanks. I did it, it worked.

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