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

Shabd Swarup V shabd at cadence.com
Wed Feb 18 11:41:20 CET 2009


Thanks a lot, Bjoern. It works perfectly! :)

Regards,
Shabd

-----Original Message-----
From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Bjoern Erik Nilsen
Sent: Wednesday, February 18, 2009 1:26 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Exact location of widget on screen.

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
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list