[Canvas class] What does zoomLevel returns compared to setZoomLevel (manual link inside)?

In manual https://api.kde.org/appscomplete-api/krita-apidocs/libs/libkis/html/classCanvas.html (canvas class)

It says this:

zoomLevel
Returns
    the current zoomlevel. 1.0 is 100%. 
setZoomLevel
setZoomLevel set the zoomlevel to the given value.

1.0 is 100%. 

So it says set takes 1.0 as 100% and zoom level returns 1.0 as 100%, or do I understand it wrong?

Because when I setZoomLevel to 1 canvas zoom is set to 100% (obviously it’s ok) but when I call zoomLevel it returns 4.1666666… not 1.0

Is there please some way to get the same values from zoomLevel as are used in setZoomLevel or is there please some way to recalculate zoomLevel to setZoomLevel?

Thank you very much

1 Like

Maybe krita is not liking the way your giving it the value to do the setZoomLevel?

I confirm, I have the same problem

from krita import * 

w = Krita.instance().activeWindow() 
v = w.activeView()
c = v.canvas()
c.setZoomLevel(1.0)
print(c.zoomLevel())

Result:

4.166666666666667

And zoom is 100% in UI:
image

But, if you set your document to 72dpi, then result is:

1.0

Not sure to understand why returned zoom level is dependent of image resolution… :thinking:
For me 100% zoom level should return 1.0, whatever image resolution is.

Grum999

1 Like

It doesn’t matter. If I jsut open the scripter and ask for the zoomLevel without doing anything else it still gives 4.16 for 100%.

I’m with you on that. That’s how I understand the docs if it says it returns 1 for 100% I’d expect the function to actually return 1 for 100% and not 4.16 :slight_smile:

ohh if it depends on dpi I’ll have to rework my script again, eghh…

You really saved me there with that 72 dpi, turns out it’s “currentDPI / 72”, no idea why it doesn’t return the value straight instead though.

maybe it is all factored into the same value to simplify the read?

I would check to several document resolution sizes and see if the relationship can be given by a straightforward formula or not. like image scale / camera scale or something similar. canvas zoom seems something that if it was wrong someone would have noticed by now but must be just weird to look at.

But I do agree that it should show the correct zoom value independent of document scaling.

Yeah it seems to work with the dpi as mentioned above (currentDPI / 72). At least all the several checks I did on different documents now.

I’ll be checking other options for new doc to see if there’s more to it.

What I have a problem the most with is that whatever the reason is, in the docs it straight forward says it returns 1.0 for 100% zoom it doesn’t say anything else. So that’s where it’s really weird. If it returns something else or based on something else or whatever I think the best would be if the docs had this mentioned there. :wink:

I think it is something.Document.resolution()

https://api.kde.org/appscomplete-api/krita-apidocs/libs/libkis/html/classDocument.html#a08b6c8e6e160f9229f36540ad3d84807

you also have this for independant dpi’s?

1 Like

Yeah, I got the resolution from the docs just when I posted the edit.

Just out of curiosity, what is your python api reference - krita tool?
Is it available please? :wink:

Could you explain to me what you mean by the second part

?

Thank you!

Not sure this can be used here as zoom result seems to be related to document resolution and not related to device resolution.
On my side changing logical resolution of device do not have impact to returned zoom level…

@nickgeneratorfailed, you can use the document resolution to calculate a factor to apply to get 1.0 when zoom is 100% and zoomLevel() return something else than 1.0
But I really think this is only a workaround and current returned value is not normal

Maybe a developer can confirm that.

Take in consideration that, if one day the problem is fixed, you may have to change the factor 1.0

Grum999

2 Likes

I think this is the link. this is one of the besttest addons around and somehow it is not featured on the resources site.

well you have reference to dpiX and dpiY. then you have them separate in normal, pdmphysical, logical and physical again. what they mean I don’t have a single clue.

1 Like

@Grum999 well whether it’s intended or it will be fixed I don’t know but for now I have to work with what I have and eventually change one line or so in my code if it gets fixed. ;0

I wonder if @halla or @tiar would know this better, please?

@EyeOdin Heh for now I’ll use just the document resolution, it gives just one number and see in the future if it will need fixing since I have no idea whether the other numbers would be needed or not.
(I’m implementing a zoom (the same thing that’s already in Krita so I think document resolution is the only dpi I’ll need)

Thanks a lot guys :wink:

physicalDpi is the native resolution of device (screen, printer, …)
logicalDpi is the resolution applied at OS level

On m y side for example, native resolution for my main display is 163dpi (returned by physicalDpi)
And I defined a resolution 144dpi in OS settings (and this is what is returned by logicalDpi)

PdmDpi are just enum values that you can use with some Qt methods to indicate in which resolution you want to work.

Grum999

2 Likes