I'm trying to zoom QQuickPaintedItems, such that things gets larger, but drawing quality does not get worse (i.e. painting is re-triggered as items gets larger).
setScale method is similar to what I want to get, but the item content is not scaled, therefore it looks bad.
setContentsScale, instead, will scale the content and trigger a re-paint, therefore the quality is high, but unluckily the content becomes also bigger than the item
I would like to obtain a combination of the two, but I can't get it to work. I tried using setContentsSize, but it's not really clear what it is used for and, moreover, I tried changing it to some random values, but I'm not experiencing any visible difference.
What is the purpose of setContentsSize?
Can it be useful to implement the zoom I'm looking for?
Is there a better alternative?
EDIT: I tried experimenting a bit, but still I didn't find an answer. A sample code to demonstrate my results is here, while a screenshot of what I get is the following:

I cannot understand why the blue rectangle is large as the yellow one, but the painting goes outside of the blue one: if you watch carefully, you can also see that the text is on a single line and it's not wrapped.
What's going on?
The problem is that QQuickPaintedItem is affected by a bug regarding this matter, see here and here.
As reported in the documentation, scaling happens both on content and on painter, therefore the blue rectangle is as expected (consistent with the doc), but not really useful.
To fix it, it is required a bit of tweaking: width() and height() shall be used to get the current item size, instead of contentsBoundingRect(), and the sizes must be set depending on the scaling factor.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With