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. Render SVG to QPixmap with unknow target size and without loss of quality
Forum Updated to NodeBB v4.3 + New Features

Render SVG to QPixmap with unknow target size and without loss of quality

Scheduled Pinned Locked Moved Solved General and Desktop
6 Posts 3 Posters 4.8k 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.
  • P Offline
    P Offline
    pvt.peter
    wrote on last edited by
    #1

    Hi,

    I have got an *.svg file and i would like to scale it into a QPixmap which has got an unknow target size.
    So when i would like to scale the *.svg file, i do not know the target size of it.

    I have used it so far:

    ...
    QPixmap(":/path/to/svgfile.svg").scaled(100, 100, Qt::KeepAspectRatio, Qt::SmoothTransformation);
    ...
    

    But I realized that it is not appropriate.
    Now the QPixmap is not pixelised, but it has got an other behavior if it appears on a responsive surface.
    Because the smooth transformated 100×100 sized image would be rescaled into a bigger surface,.
    And we are again at the beginning, the image is pixelised.

    How can i reach the next?

    • render QPixmap from *.svg file when the target size is known

    Thanks for advance,
    Peter

    1 Reply Last reply
    0
    • ? Offline
      ? Offline
      A Former User
      wrote on last edited by
      #2

      Hi! Can't you just use QSvgWidget Class?

      P 1 Reply Last reply
      2
      • ? A Former User

        Hi! Can't you just use QSvgWidget Class?

        P Offline
        P Offline
        pvt.peter
        wrote on last edited by pvt.peter
        #3

        Hi @Wieland,

        Thanks for reply and sorry for my late reply.
        Unfortunately QSvgWidget class can not use in this case.

        Any other solution about it?

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mostefa
          wrote on last edited by mostefa
          #4

          Hi @pvt-peter ,

          If you can not use QSvgWidget as suggested by @Wieland ,and If you are not obliged to use QPixmap

          You can do something like this:

          Have QWidget named imageContainerWidget;

          Change stylesheet to imageContainerWidget as follows:

          QWidget#imageContainerWidget
          {
          	   image: url(":/images/path/to/svgfile.svg");
          }
          

          And that's it !

          When your imageContainerWidget is resized your image will be resized too,

          The result will be then something like this:

          Before resizing:

          alt text

          After resizing:

          alt text

          Hope this can help!

          P 1 Reply Last reply
          3
          • M mostefa

            Hi @pvt-peter ,

            If you can not use QSvgWidget as suggested by @Wieland ,and If you are not obliged to use QPixmap

            You can do something like this:

            Have QWidget named imageContainerWidget;

            Change stylesheet to imageContainerWidget as follows:

            QWidget#imageContainerWidget
            {
            	   image: url(":/images/path/to/svgfile.svg");
            }
            

            And that's it !

            When your imageContainerWidget is resized your image will be resized too,

            The result will be then something like this:

            Before resizing:

            alt text

            After resizing:

            alt text

            Hope this can help!

            P Offline
            P Offline
            pvt.peter
            wrote on last edited by
            #5

            @mostefa: Thanks for your detailed reply.
            It is a good solution.

            M 1 Reply Last reply
            0
            • P pvt.peter

              @mostefa: Thanks for your detailed reply.
              It is a good solution.

              M Offline
              M Offline
              mostefa
              wrote on last edited by
              #6

              @pvt.peter said in Render SVG to QPixmap with unknow target size and without loss of quality:

              @mostefa: Thanks for your detailed reply.
              It is a good solution.

              You are welcome =)

              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