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
Forum Updated to NodeBB v4.3 + New Features

QQuickImageProvider::requestImage() ignore size param values

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
8 Posts 2 Posters 1.6k Views 2 Watching
  • 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.
  • D Offline
    D Offline
    deleted57
    wrote on 19 Feb 2018, 11:12 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

    R 1 Reply Last reply 19 Feb 2018, 12:19
    0
    • D deleted57
      19 Feb 2018, 11:12

      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

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 19 Feb 2018, 12:19 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
      • D Offline
        D Offline
        deleted57
        wrote on 19 Feb 2018, 12:52 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...

        R 1 Reply Last reply 19 Feb 2018, 13:22
        0
        • D deleted57
          19 Feb 2018, 12:52

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

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 19 Feb 2018, 13:22 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
          • D Offline
            D Offline
            deleted57
            wrote on 19 Feb 2018, 14:31 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

            R 1 Reply Last reply 19 Feb 2018, 14:40
            0
            • D deleted57
              19 Feb 2018, 14:31

              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

              R Offline
              R Offline
              raven-worx
              Moderators
              wrote on 19 Feb 2018, 14:40 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
              • D Offline
                D Offline
                deleted57
                wrote on 19 Feb 2018, 15:00 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...

                R 1 Reply Last reply 20 Feb 2018, 08:00
                0
                • D deleted57
                  19 Feb 2018, 15:00

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

                  R Offline
                  R Offline
                  raven-worx
                  Moderators
                  wrote on 20 Feb 2018, 08:00 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

                  1/8

                  19 Feb 2018, 11:12

                  • Login

                  • Login or register to search.
                  1 out of 8
                  • First post
                    1/8
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved