Qt 6.11 is out! See what's new in the release
blog
Height and width of the image with unknow sizes
QML and Qt Quick
2
Posts
2
Posters
2.1k
Views
1
Watching
-
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: myImageComponent.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":http://qt-project.org/doc/qt-4.8/propertybinding.html or signals onWidthChanged and onHeightChanged