What is the best way to get size of widget in viewport?

I know this is an old question but it is among the first results in google and it’s not answered so the answer is you need to get the cached geometry and either get the local size or the absolute size.

The absolute size will get you the size based on the the window resolution so you’d get dynamic results based on your current resolution while local size will get you the local size in local space, try both and see which one you want to use.

There’s one thing that is very important to keep in mind, you will get (0, 0) if the widget is not in viewport or if you instantly try to get this value right after adding the widget to the viewport, so you just added the widget to the viewport you need to wait a few milliseconds before you can retrieve the size, you can do a loop+delay until size > 0.

6 Likes