The x() and y() functions return the relative coordinates of a widget to its parent. Is there a simple way to find the absolute coordinates of a widget in a window (rather than iterating up parents to the window)?
thanks, Richard
The x() and y() functions return the relative coordinates of a widget to its parent. Is there a simple way to find the absolute coordinates of a widget in a window (rather than iterating up parents to the window)?
thanks, Richard
you can use QWidget::mapToGlobal(const QPoint & pos) which gives you pos translated to global coordinates
I would like to be a "Guru"
Useful hints (try them before asking):
- Use Qt Assistant
- Search the forum
If you haven't found solution yet then create new topic with smart question.
Hossein (22nd October 2015)
thanks for the reply faldżip.
Unfortunately mapToGlobal() gives the result in screen coordinates, meaning that it is dependent on the location of the window.
Try this:
It's probably equivalent to:
Qt Code:
while(from && from!=wnd){ pt = from->mapToParent(pt); from = from->parent(); } return pt; }To copy to clipboard, switch view to plain text mode
Cupidvogel (20th November 2015), rbp (28th January 2009), TheIndependentAquarius (15th March 2017)
thanks (again) wysota.
Bookmarks