Qt designer shows svg in QLabel, but it's invisible.
-
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. -
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.
-
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.@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
QLabeland the SVG image is a resource, you can look at theui_....hfile generated from your.ui(Designer) file to see how that is done, and compare against your code. Everything from the.uigoes into that.hfile, there is no other "magic".EDIT
Oh, I see, you are saying aQSvgWidgetdoes work, but aQLabelwith 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 claimsQLabel::setPixmap()on aQPixmap pix("imagelocation.svg")does show. Are you usingQPixmap()? 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.