QImage svg dimensions incorrect
-
I have a QML image specified in my QML file as follows:
Image { id: imageTest x: 10 y: 10 width: 190 height: 124 source: Qt.resolvedUrl("Images/Image.svg") sourceSize.width: 190 sourceSize.height: 124 }
From my understanding, and reading through the Qt documentation, this should set the QSize of the image to (190, 124).
However, in a c++ class, I read the QSize properties of the image through its URL as such:
void MaskedMouseArea::setMaskSource(const QUrl &source) { if (m_maskSource != source) { m_maskSource = source; m_maskImage = QImage(QQmlFile::urlToLocalFileOrQrc(source)); qDebug() << m_maskImage; emit maskSourceChanged(); } }
The QDebug() provides the following:
QImage(QSize(142, 93),format=6,depth=32,devicePixelRatio=1,bytesPerLine=568,byteCount=52824)
I've tried changing the width, sourceSize.width, height and sourceSize.height properties of the QML image which doesn't have any effect.
What am I missing here?
-
@jars121
A SVG is a vector graphic image format. That means it can be scaled to an arbitrary size.
QImage is rasterized, means it needs a defined size.Now i do not know if the SVG format supports to define a predefined size in it's data nor how the QSvgImageFormat plugin works. But for sure any size has to be defined when rasterizing a SVG image of course. My assumption is that simply a default size is chosen. So i wouldn't rely on it.
-
@raven-worx Thanks for your input, your understanding/interpretation is the same as mine.
The Qt documentation has the following to say about the setSize property of the Image QML type:
If the source is an intrinsically scalable image (eg. SVG), this property determines the size of the loaded image regardless of intrinsic size. Avoid changing this property dynamically; rendering an SVG is slow compared to an image.
My understanding is that by setting the size of the SVG (via setSize) it allocates it the required raster size, which should then be read correctly elsewhere? No matter what I do to the SVG, it always reads the same incorrect size.