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. QQuickImageProvider::requestImage() ignore size param values
QtWS25 Last Chance

QQuickImageProvider::requestImage() ignore size param values

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 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.
  • deleted57D Offline
    deleted57D Offline
    deleted57
    wrote on last edited by
    #1

    Hi all

    I'm developing an app made in QML and using QQuickImageProvider::requestImage() provider for load custom images. Based to the documentation it seem that the *size param have to be filled with the image width and height to use in case they are not set into QML Image {} item. However, in my experiment, it seem QML engine totally ignore the *size values I set and use as params the width and height got from the QImage object returned.
    Is this behaviour normal and I missed some point in t he use of this function or there is some other problem?
    Thank you

    raven-worxR 1 Reply Last reply
    0
    • deleted57D deleted57

      Hi all

      I'm developing an app made in QML and using QQuickImageProvider::requestImage() provider for load custom images. Based to the documentation it seem that the *size param have to be filled with the image width and height to use in case they are not set into QML Image {} item. However, in my experiment, it seem QML engine totally ignore the *size values I set and use as params the width and height got from the QImage object returned.
      Is this behaviour normal and I missed some point in t he use of this function or there is some other problem?
      Thank you

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

      @Suppaman
      the docs say:

      In all cases, size must be set to the original size of the image. This is used to set the width and height of the relevant Image if these values have not been set explicitly.

      QQuickImageProvider never is responsible in which size the image should be displayed.

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

      1 Reply Last reply
      0
      • deleted57D Offline
        deleted57D Offline
        deleted57
        wrote on last edited by
        #3

        never is responsible is ok, but from my understanding the param *size is needed for know the size of the image in case an explicit width and heigh was not set inside Image {}. However it doesn't seem the case...

        raven-worxR 1 Reply Last reply
        0
        • deleted57D deleted57

          never is responsible is ok, but from my understanding the param *size is needed for know the size of the image in case an explicit width and heigh was not set inside Image {}. However it doesn't seem the case...

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

          @Suppaman
          May it be that you mix up the Image element's sourceSize and the actual item size?

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

          1 Reply Last reply
          0
          • deleted57D Offline
            deleted57D Offline
            deleted57
            wrote on last edited by
            #5

            No, QML code is really basic as follow:

            Image {
                        anchors.centerIn: parent
                        source: "image://MyProvider/MyImage"
                        cache: false
                    }
            

            And the C++ side:

            QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
            {
                QImage Image;
            
                 // Load image of 70x70 (example) from somewhere
                 // .....
            
               *size = QSize(400, 400);//Set as try, this value is totally ignored
            
                return Image;
            }
            

            The image showed is always 70x70

            raven-worxR 1 Reply Last reply
            0
            • deleted57D deleted57

              No, QML code is really basic as follow:

              Image {
                          anchors.centerIn: parent
                          source: "image://MyProvider/MyImage"
                          cache: false
                      }
              

              And the C++ side:

              QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
              {
                  QImage Image;
              
                   // Load image of 70x70 (example) from somewhere
                   // .....
              
                 *size = QSize(400, 400);//Set as try, this value is totally ignored
              
                  return Image;
              }
              

              The image showed is always 70x70

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

              @Suppaman said in QQuickImageProvider::requestImage() ignore size param values:

              The image showed is always 70x70

              Because there is no more image data than 70x70 available.
              Again...the QQuickImageProvider doesn't decide how big an image is displayed. You should always set size to the actual size of the loaded image.

              If you want to control the scaling do this instead:

              QImage MyImageProvider::requestImage(const QString &id, QSize *size, const QSize &requestedSize)
              {
                  QImage Image;
              
                   // Load image of 70x70 (example) from somewhere
                   // .....
                  
                 Image = Image.scaled(400,400,Qt::KeepAspectRatio,Qt::SmoothTransformation);
              
                 *size = Image.size();
              
                  return Image;
              }
              

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

              1 Reply Last reply
              1
              • deleted57D Offline
                deleted57D Offline
                deleted57
                wrote on last edited by
                #7

                Sorry, probably I explained wrong my problem. I know QQuickImageProvider just get the image and pass to the QML layer but in my example code I expected on QML side the image will be scaled to 400x400 since I passed to the size param this values and, based to the documentation, I should "inform" QML Image {} item that the image to show have 400x400 size. Basically same result of this:

                Image {
                            anchors.centerIn: parent
                            source: "image://MyProvider/MyImage"
                            cache: false 
                           width: 400
                          height: 400
                        }
                

                However this not happen and the image showed is always 70x70 (also the size of Image item is 70x70 as obvious). It seem the Image {} get the image size from Image.size() instead of *size param...

                raven-worxR 1 Reply Last reply
                0
                • deleted57D deleted57

                  Sorry, probably I explained wrong my problem. I know QQuickImageProvider just get the image and pass to the QML layer but in my example code I expected on QML side the image will be scaled to 400x400 since I passed to the size param this values and, based to the documentation, I should "inform" QML Image {} item that the image to show have 400x400 size. Basically same result of this:

                  Image {
                              anchors.centerIn: parent
                              source: "image://MyProvider/MyImage"
                              cache: false 
                             width: 400
                            height: 400
                          }
                  

                  However this not happen and the image showed is always 70x70 (also the size of Image item is 70x70 as obvious). It seem the Image {} get the image size from Image.size() instead of *size param...

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

                  @Suppaman
                  either scale the image in the imageprovider (as i've shown) or adjust the sourceSize of the Image element.
                  Again nevertheless always set the size parameter of the actual size of the returned image.

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

                  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