PDA

View Full Version : Getting a widget's position in desktop coords?



gfunk
5th January 2007, 00:23
I'm trying to display a popup that appears relative to the button that opens it, and not be constrained by the window of the button's parent. And it seems that to set the popup dialog position (via QWidget::move()), I have to specify it in desktop coordinates. But I can't seem to find an easy way to find the geometry of the button in desktop coordinates; QWidget:: pos() returns relative coords to the parent.

The best I can do is QCursor:: pos(), but that's just the mouse cursor, not the button. Do I have to just traverse up all the parents, and add up the relative positions of the widgets to their parents, until I hit a toplevel window widget (which should have pos() returning desktop coords)?

jpn
5th January 2007, 06:17
QWidget::mapToGlobal() translates coordinates relative to a widget to the global screen coordinates.