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. Height and width of the image with unknow sizes
Qt 6.11 is out! See what's new in the release blog

Height and width of the image with unknow sizes

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 2 Posters 2.1k Views 1 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.
  • M Offline
    M Offline
    michprev
    wrote on last edited by
    #1

    Hi,
    I load images from the Internet to Flickable and I need to get their sizes (for set Flickable contentWidth).
    They have various sizes so I do not set width and height to Image element.

    @
    Image {
    id: myImage

    Component.onCompleted: {
        myImage.source = "adressOfTheImage";
        console.log(myImage.width, myImage.height); // 0, 0
        console.log(myImage.paintedWidth, myImage.paintedHeight); // 0, 0
    }
    

    }
    @

    1 Reply Last reply
    0
    • T Offline
      T Offline
      task_struct
      wrote on last edited by
      #2

      Hi,

      QML Image documentation says:
      bq. If the width and height properties are not specified, the Image element automatically uses the size of the loaded image.

      Your log shows 0.0 because @myImage.source = "adressOfTheImage";@ does not load image immediately. You can use "property bindings":http://qt-project.org/doc/qt-4.8/propertybinding.html or signals onWidthChanged and onHeightChanged

      "Most good programmers do programming not because they expect to get paid or get adulation by the public, but because it is fun to program."

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