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. Qt designer shows svg in QLabel, but it's invisible.
Forum Updated to NodeBB v4.3 + New Features

Qt designer shows svg in QLabel, but it's invisible.

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 4 Posters 1.6k Views
  • 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.
  • MegamouseM Offline
    MegamouseM Offline
    Megamouse
    wrote on last edited by
    #1

    Using the designer of Qt 5.15.2, I replaced the png resource of a QLabel with an svg.
    The image looks fine in the designer, but it's invisble during runtime.
    I set the label to 50x50 max-size expanding.

    I'm using a QSvgWidget in another dialog, and it works fine.

    It's not a big deal, I can just use another QSvgWidget here as well, but I am wondering if I'm doing something wrong,
    or if this is a Qt bug.

    JonBJ 1 Reply Last reply
    0
    • C Offline
      C Offline
      ChrisW67
      wrote on last edited by
      #2

      You are most likely using a path to the SVG file that is incorrect or have not deployed the SVG plugin.
      Given the QSvgWidget is working, the first option seems most likely.
      Commonly this is because of a relative file path and incorrect assumption about the current working directory of the program.

      Just a guess because we cannot see your code.

      1 Reply Last reply
      0
      • MegamouseM Offline
        MegamouseM Offline
        Megamouse
        wrote on last edited by
        #3

        The svg is selected from the resource file.
        I use the same path when loading it manually in the QSvgWidget.

        Whether or not I have the QSvg.dll in my application directory or not does not make any difference.

        1 Reply Last reply
        0
        • B Offline
          B Offline
          Bonnie
          wrote on last edited by
          #4

          Do you also have imageformats/qsvg.dll in your plugin folder?

          1 Reply Last reply
          0
          • MegamouseM Megamouse

            Using the designer of Qt 5.15.2, I replaced the png resource of a QLabel with an svg.
            The image looks fine in the designer, but it's invisble during runtime.
            I set the label to 50x50 max-size expanding.

            I'm using a QSvgWidget in another dialog, and it works fine.

            It's not a big deal, I can just use another QSvgWidget here as well, but I am wondering if I'm doing something wrong,
            or if this is a Qt bug.

            JonBJ Online
            JonBJ Online
            JonB
            wrote on last edited by JonB
            #5

            @Megamouse said in Qt designer shows svg in QLabel, but it's invisible.:

            I'm using a QSvgWidget in another dialog, and it works fine.

            If that too is using a QLabel and the SVG image is a resource, you can look at the ui_....h file generated from your .ui (Designer) file to see how that is done, and compare against your code. Everything from the .ui goes into that .h file, there is no other "magic".

            EDIT
            Oh, I see, you are saying a QSvgWidget does work, but a QLabel with an SVG for an image does not. My bad. Then I don't know.... Example at, say, https://forum.qt.io/topic/94244/adjust-an-svg-image-to-qlabel claims QLabel::setPixmap() on a QPixmap pix("imagelocation.svg") does show. Are you using QPixmap()? You need to.

            You might want to read the discussion in https://stackoverflow.com/questions/35129102/simple-way-to-display-svg-image-in-a-pyqt-window/35138314.

            Actually, although it's Qt 4.8, you look like you might be in the same situation as https://www.qtcentre.org/threads/48710-Qt-4-8-QLabel-not-showing-SVG-QButton-does, which is also worth reading.

            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