0
votes

I'm using the

Item.grabToImage()

But I'm getting the following error.

QML ItemX: grabToImage: item has invalid dimensions

This is because I'm using height and width properties like so:

width: {
    // return with * 0.4; based for some condition
    // for eg
    return parent.width * 0.4;
}

// and something similar with height

The only time that I can get the following code working is when I put in a static heigth and width:

grabToImage(
    function(result)
    {
        result.saveToFile("/path/project-name/tmp/something.png");
    }
);

Any ideas of why and how do I get around this problem?

Thank you

1
Did you consider the possibility that ... well... your dimensions might be invalid?dtech
well I presume that because I can see it, resize it according to the width of the parent width and even scales with the window that the size must be valid in some way. If they we're invalid the rendering would be impossible. would it not?TheMan68
Sometimes the parent is not the item you think, but an internal invisible contentItem. Just to be sure, try outputting the dimension values in the console.dtech
Ok mate. I will do. This is a work issue so it'll have to be monday. Ill get back to you then. n Thanks for the feed back so farTheMan68
Probably the problem is related to your parent and/or to nesting of your elements. I do recommend you to prepare clean minimal working example, test on it and if still refuse to work as expected -- share your sources so we can help you.tro

1 Answers

1
votes

I'm not a 100% sure why, But it was something about the dynamic width of the parent.

In the program I wrote I has set the anchors of the image to the left and right of the preview container.

So when I tried to get the image capture from another item that was overlaying the image to cut out smaller parts of the image it was not letting me. How I fixed this was to set a fixed image size of the source image and then just anchor it to the center of the preview section.

The only thing is now it will not size up if you scale the window. I'm sure I could implement and on size change to the main program window and then set the width of the image (Not tested).

Last thing I should mention is that if the image is small then the cut out images from sections of the source image will be blurry and not good quality. I fixed this by setting the "sourceSize.width" to a very large image and then used the "scale" property to scale down the image to fit within the preview item.