[Qt-interest] Exact location of widget on screen.

Bjoern Erik Nilsen bnilsen at trolltech.com
Wed Feb 18 08:56:26 CET 2009


Hi,

Shabd Swarup V wrote:
> Hi,
> 
>  
> 
> I need to determine the *exact* coordinates of a widget on screen. I 
> think *geometry() *gives the location relative to the window and using 
> *frameGeometry() *does not work well either.
> 
>  
> 
> Please let me know how to do this.

First take a look at http://doc.trolltech.com/4.5/geometry.html

Notice that frameGeometry() is relevant only for top-level windows. I'm 
guessing you are interested in the global position (screen coordinates) 
for a child widget. Here's how you do it:

const QPoint globalPos = child->mapToGlobal(QPoint(0, 0));

Then you'll map (0, 0) of the child widget to global coordinates. You 
can also use mapFromGlobal the other way around.

Hope this helps,
-- 
Bjørn Erik Nilsen
Software Engineer
Nokia, Qt Software



More information about the Qt-interest-old mailing list