Scaling QtQuick painted items

I am trying to increase QQuickPaintedItem

s so that things get bigger, but the quality of the drawing does not degrade (i.e. the painting starts again as the items grow larger).

setScale

the method is similar to what I want to get, but the content of the element doesn't scale, so it looks bad.

setContentsScale

will instead scale the content and trigger re-paint, so the quality is high, but unfortunately the content also becomes larger than the element

I would like to get a combination of the two, but I cannot get it to work. I tried to use setContentsSize

, but it is not really clear what it is used for, and what is more, I tried to change it to some random values, but I am not experiencing any visible difference.

What's the purpose setContentsSize

? Could it be helpful to implement the scale I am looking for? Is there a better alternative?

EDIT: I tried experimenting a bit, but still I couldn't find an answer. Sample code to showcase my results: here , and the screenshot I get is the following:

enter image description here

I can't figure out why the blue rectangle is as big as yellow, but the picture goes beyond the blue: if you look closely, you can also see that the text is on one line and not wrapped.

What's happening?

+3


source to share


1 answer


The problem is that it is QQuickPaintedItem

affected by the error in this question, see here and.

As the documentation says, scaling happens in both content and painting, so the blue rectangle is as expected (as per the doc), but not very useful.



To fix this, a little tweak is required: width()

and height()

should be used to get the current size of the element instead of contentsBoundingRect()

, and the dimensions should be set based on the scaling factor.

+1


source







All Articles