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. Help with QGraphicsSvgItem
Forum Updated to NodeBB v4.3 + New Features

Help with QGraphicsSvgItem

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 2 Posters 1.7k 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.
  • N Offline
    N Offline
    ncnai
    wrote on last edited by
    #1

    Hello all,

    I am trying to display a svg image using QGraphicsSvgItem but what comes out is very different than what is expected.

    Here is the code I currently have to attempt displaying the svg file:

    QGraphicsScene *scene = new QGraphicsScene();
    QGraphicsSvgItem *svg = new QGraphicsSvgItem(QString("brackets.svg"));
    scene->addItem(svg);
    ui->graphicsView->setScene(scene);
    ui->graphicsView->show();
    

    Contents of brackets.svg: https://pastebin.com/90AYtckw (can verify the expected output here: https://www.rapidtables.com/web/tools/svg-viewer-editor.html just copy paste the contents and click the magnifying glass to view)

    What is expected:
    0_1526886475131_2018-05-21_00-07-27.png

    What I get from the above code in the graphicsView:
    0_1526886551648_2018-05-21_00-08-56.png

    Am I missing a step in my code to get this svg file to display properly? I have looked around but cannot tell if there is something wrong with my code or I am missing something.

    Thanks for your help.

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi and welcome to the forums
      What are they grey rects ?
      Do you insert any other items besides the QGraphicsSvgItem ?

      It kinda looks it just behind the grey ones.

      Items have zorder which is determined by the insert order unless changed via
      http://doc.qt.io/qt-5/qgraphicsitem.html#setZValue

      So if you do insert say some Rect items, just insert SVG last and it will be on top.

      1 Reply Last reply
      0
      • N Offline
        N Offline
        ncnai
        wrote on last edited by ncnai
        #3

        Hello and thank you,

        No, the QGraphicsSvgItem is the only item I have added to the scene.
        Just to check, I called scene->clear() before I added the QGraphicsSvgItem but the result is the same.

        1 Reply Last reply
        0
        • mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by mrjj
          #4

          @ncnai

          Ahh, its all inside the SVG. ( just viewed it)
          Maybe it uses features Qt SVG do not support. Qt SVG is is not latest revision.
          I will try to export it from inkscape and see.

          Hmm. Inkscape also find the SVG odd. its seems to uses groups/layers in some odd way.
          I cant edit all elements and even ungrouping do not help.

          Ok so its just in layers/combined objects.

          How/what app did you draw it ?
          I think you need to make a simpler/other version to have it drawn properly in Qt.
          If i collapse the layers in Inkscape it get a bit messy just like Qt shows it.

          So I think you need a more flat version :)

          1 Reply Last reply
          0
          • N Offline
            N Offline
            ncnai
            wrote on last edited by
            #5

            Ahh I see, thank you for the information! I am not too familiar at working with SVG. The file I obtained was downloaded off of Challonge so I am not too sure how they are drawing it exactly, but if Qt is having trouble drawing it properly I will try to seek out some alternatives.

            Also as a fun side note I tried loading the file through a QXmlStreamReader, passing the reader to a QSvgRenderer, and then sharing it with my QGraphicsSvgItem. What came out was the Challonge logo (the top part of what was expected) but nothing else.

            Anyways thanks for your help :)

            mrjjM 1 Reply Last reply
            1
            • N ncnai

              Ahh I see, thank you for the information! I am not too familiar at working with SVG. The file I obtained was downloaded off of Challonge so I am not too sure how they are drawing it exactly, but if Qt is having trouble drawing it properly I will try to seek out some alternatives.

              Also as a fun side note I tried loading the file through a QXmlStreamReader, passing the reader to a QSvgRenderer, and then sharing it with my QGraphicsSvgItem. What came out was the Challonge logo (the top part of what was expected) but nothing else.

              Anyways thanks for your help :)

              mrjjM Offline
              mrjjM Offline
              mrjj
              Lifetime Qt Champion
              wrote on last edited by
              #6

              @ncnai
              Yeah i also fooled around with it. it seems Qt do not understand the
              sub objects. For fun , i recreated same layout using boxes and Qt had no issues
              with that so it should be possible to do as you want with a less advanced version.
              You can use inkscape (free software) to create a new version with same look.
              Should not be that complicated. Inkscape also acted a bit odd on that file as
              it would sort of collapse if i copy & pasted to new sheet. Not seen that before.

              1 Reply Last reply
              1

              • Login

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