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. QImage svg dimensions incorrect

QImage svg dimensions incorrect

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
4 Posts 2 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.
  • J Offline
    J Offline
    jars121
    wrote on last edited by
    #1

    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?

    raven-worxR 1 Reply Last reply
    0
    • J Offline
      J Offline
      jars121
      wrote on last edited by
      #2

      Any thoughts on this? It has me considerably stumped!

      1 Reply Last reply
      0
      • J jars121

        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?

        raven-worxR Offline
        raven-worxR Offline
        raven-worx
        Moderators
        wrote on last edited by
        #3

        @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.

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        J 1 Reply Last reply
        0
        • raven-worxR raven-worx

          @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.

          J Offline
          J Offline
          jars121
          wrote on last edited by
          #4

          @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.

          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