Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. Is it posible to display SVG in Qt(5.3) TextEdit without loosing quality?
Forum Updated to NodeBB v4.3 + New Features

Is it posible to display SVG in Qt(5.3) TextEdit without loosing quality?

Scheduled Pinned Locked Moved QML and Qt Quick
3 Posts 2 Posters 1.1k 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.
  • ? Offline
    ? Offline
    A Former User
    wrote on last edited by
    #1

    I have svg image with this attributes: viewBox="0 0 100 100"

    This is basic code which I use for displaying svg:

    @Image{
    width: 50
    height: 50
    source: "test.svg"
    }@

    and it's not ok because image is rasterized before resizing to width and height values(50,50).

    This code works perfect on all resolution:

    @Image{
    width: 50
    height: 50
    sourceSize.width: width
    sourceSize.height: height
    source: "test.svg"
    }@

    because image is drawn in exact dimensions which is needed!

    Is it posible to get same functionality in a TextEdit where <img> tag is used?

    < img src="test.svg" width="50" height="50" >

    This code doesn't work because sourceSize can't be set... and image is rasterized before resizing and displaying...

    Maybe there is some other way to accomplish this?

    The main goal is displaying some text and some inline images(like smileys in chat application). I use TextEdit because it can display RichText(html in this case), and that html normaly works in IE or FF browser - the svg looks perfect. Why it's not working in Qt? Is there any other way to mix text and images?

    1 Reply Last reply
    0
    • shavS Offline
      shavS Offline
      shav
      wrote on last edited by
      #2

      Hi,

      If you don't need custom images you can user UTF-8 Emoji. All list you can find "here":http://apps.timwhitlock.info/emoji/tables/unicode. I think you can try to find some way to change the image from standard.

      Also you can try to create SVG image with width and height which you need to display. In your case you need to set attribute viewBox=“0 0 50 50”. It's must help to you solve the problem. If you need to support retina icons. You can use code to check the display type (retina or non-retina) and then update image (change path to image).

      In C++
      @
      //Subscribe to signal of activate all available screens.
      foreach(QWindow* wnd, qApp->allWindows())
      {
      connect(wnd, SIGNAL(screenChanged(QScreen*)), SLOT(onWindowDidCahngeScreen(QScreen*)));
      }

      //Slot Implementation
      void Manger::onWindowDidCahngeScreen(QScreen* newScreen)
      {
      QWindow* wnd = (QWindow*)sender();
      if(wnd == qApp->focusWindow())
      {
      bool isRetina = (newScreen->devicePixelRatio() == 2);
      emit screenDidChange(isRetina, getScreenSize()); //Send signal to QML
      }
      }
      @

      In QML:
      @
      property string retinaSufix: ""

      Component.onCompleted: {
      manager.screenDidChange.connect(function (isRetina, size) {
      retinaSufix = (isRetina === true) ? "@2x" : "";
      });
      }

      Image {
      width: 50
      height: 50
      source: "test" + retinaSufix + ".svg"
      }
      @

      Also you need two images first for non-retina display and second for retina display. In your case test.svg (50x50) and test@2x.svg (100x100).

      I using this in my project but I use this code with PNG files and don't tested on SVG.

      I hope this help you to solve your problem.

      Mac OS and iOS Developer

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

        Thank you @shav. I need to resize my custom svg images depending on screen dpi. Maybe that will be posible to achieve with a new web engine in Qt 5.4. For now it seems that's not possible...

        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