Results 1 to 5 of 5

Thread: Absolute widget coordinates

  1. #1
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Absolute widget coordinates

    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

  2. #2
    Join Date
    Jan 2008
    Location
    Poland
    Posts
    687
    Thanks
    4
    Thanked 140 Times in 132 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Absolute widget coordinates

    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):
    1. Use Qt Assistant
    2. Search the forum

    If you haven't found solution yet then create new topic with smart question.

  3. The following user says thank you to faldzip for this useful post:

    Hossein (22nd October 2015)

  4. #3
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Absolute widget coordinates

    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.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Absolute widget coordinates

    Try this:
    Qt Code:
    1. QPoint localPoint = ...
    2. QPoint windowPoint = myWidget->mapTo(myWidget->window(), localPoint);
    To copy to clipboard, switch view to plain text mode 

    It's probably equivalent to:
    Qt Code:
    1. QPoint mapToWindow(QWidget *from, QPoint pt){
    2. QWidget *wnd = from->window();
    3. while(from && from!=wnd){
    4. pt = from->mapToParent(pt);
    5. from = from->parent();
    6. }
    7. return pt;
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. The following 3 users say thank you to wysota for this useful post:

    Cupidvogel (20th November 2015), rbp (28th January 2009), TheIndependentAquarius (15th March 2017)

  7. #5
    Join Date
    May 2008
    Location
    Melbourne, Australia
    Posts
    136
    Thanks
    9
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Absolute widget coordinates

    thanks (again) wysota.

Similar Threads

  1. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 08:06
  2. Widget Focus
    By navi1084 in forum Qt Programming
    Replies: 6
    Last Post: 29th September 2008, 11:22
  3. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 21:39
  4. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 11:35
  5. return of absolute coordinates in svg-graphics
    By hulk in forum Qt Programming
    Replies: 2
    Last Post: 22nd February 2006, 13:23

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.