Important: Please read the Qt Code of Conduct -

Height and width of the image with unknow sizes

  • 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


  • 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": or signals onWidthChanged and onHeightChanged

Log in to reply