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. Loading svg from char buffer
Forum Updated to NodeBB v4.3 + New Features

Loading svg from char buffer

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 404 Views 2 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.
  • F Offline
    F Offline
    FroZtiZ
    wrote on last edited by
    #1

    Dear community,

    Currently I have a soft that creates png image inside a char*.
    It is quite easy to load it in a QPixmap using the QPixmap::loadFromData() function

    QPixmap pic;
    pic.loadFromData((const uchar*)buf, len, "png");
    

    This image is then rendered inside a QScrollArea

    ui->scrollArea->setWidget(pic);
    

    I want to evolve my code and use svg instead of png to avoid losing quality when zooming in.
    I have no idea where to start.
    I looked at QGraphicsSvgItem, QSvgGenerator, QSvgWidget but there is no similar option to load from a char*...
    Any idea by what I can replace QPixmap to take my svg instead of png and how to render it ?

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

      Hi,

      Use QSvgRenderer to render it on your QPixmap.

      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
      0
      • F Offline
        F Offline
        FroZtiZ
        wrote on last edited by FroZtiZ
        #3

        Thanks SGaist.
        So globally what you tell me is (where "buf" is a char* and contains the svg code):

        QPixmap pic;
        pic.loadFromData((const uchar*)buf, len, "svg");
        QSvgRenderer(pic);
        

        Is that your suggestion?

        M 1 Reply Last reply
        0
        • F FroZtiZ

          Thanks SGaist.
          So globally what you tell me is (where "buf" is a char* and contains the svg code):

          QPixmap pic;
          pic.loadFromData((const uchar*)buf, len, "svg");
          QSvgRenderer(pic);
          

          Is that your suggestion?

          M Offline
          M Offline
          mpergand
          wrote on last edited by
          #4

          @FroZtiZ
          I think you have to convert your char buffer to QByteArray first, then use:
          QSvgRenderer(const QByteArray &contents, QObject *parent = nullptr)

          1 Reply Last reply
          1
          • F Offline
            F Offline
            FroZtiZ
            wrote on last edited by
            #5

            Oh ok I understand the strategy. Thanks a lot

            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