How to use SVG
-
No that's the Qt Creator version. There's no Qt 4.14.
You have to take a look at the kit you are using.
-
It was introduced from 4.1.
https://doc.qt.io/qt-5/qsvgwidget.html
QT += core gui widgets svg <=== you need widgets as well for qsvgwidgetIf you simply need a QPixmap from a svg source for other widgets, use QSvgRenderer to paint one.
-
Drop the C++ CONFIG, you do not need that currently.
You should also consider updating to the latest Qt 6.1.
-
-
Hi
Else a sure bet is installing Qt5.15.
While v6 does offer new things
https://wiki.qt.io/New_Features_in_Qt_6.0
Its mostly if you are using QML and it still has lots of features missing planned
for some later releases. -
- Why isn't there a widget for SVG in QT Designer by default?
Too much work I would guess. To allow a Widget to be used in design time, a plugin must be made and maintained across many Designers.
And QSvgWidget doesn't have any properties to set at Design time. (besides the svg file) so I gues sit was
not worth the effort.You can use the Producer Promote feature to allow a Qwidget as a place holder in Designer and then app is run its
the SVG one. -
Hi
Its very handy.In your use case you place a QWidget on the form, right-click and choose to promote.
Then tell it QSvgWidget for class name and it will guess on QSvgWidget.h
Then press Add (+), then then promote.https://doc.qt.io/qt-5/designer-using-custom-widgets.html
Do note:
Accessing it via Ui-> is possible and you can call the real functions from code, just like any other widget. -
So, if I want to create a custom widget for SVG, how can I do that? Is there an example that I can follow for promoting a widget to SVG?
(I ask this because I really want to use SVG as default and I need a solution.)
(I am also a beginner so I have no idea where to start :) ) -
So i am using Qt 6.2.2 & ran into the same problem the solution was :
in the .pro file its QT+= svg svgwidgets
now you can#include <QSvgWidgets>
found it in the included svgviewer example in QT qtsvg-svgviewer-example
hope i helped
-
As explained here,
QSvgWidget
has been moved to a new module calledQtSvgWidgets
. According to the documentation:Header: #include <QSvgWidget> CMake: find_package(Qt6 REQUIRED COMPONENTS SvgWidgets) target_link_libraries(mytarget PRIVATE Qt6::SvgWidgets) qmake: QT += svgwidgets Inherits: QWidget So in Qt6 the solution is following:
QT += svgwidgets