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

so you just added the widget to the
viewport you need to wait a few
milliseconds before you can retrieve
the size

That’s what Force Layout Prepass is for. Otherwise you’re getting stale data. Or data that’s not ready.