Results 1 to 2 of 2

Thread: Getting a widget's position in desktop coords?

  1. #1
    Join Date
    Apr 2006
    Location
    San Francisco, CA
    Posts
    186
    Thanks
    55
    Thanked 12 Times in 11 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Getting a widget's position in desktop coords?

    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)?
    Last edited by gfunk; 5th January 2007 at 00:29.
    Software Engineer



  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Getting a widget's position in desktop coords?

    QWidget::mapToGlobal() translates coordinates relative to a widget to the global screen coordinates.
    J-P Nurmi

  3. The following 2 users say thank you to jpn for this useful post:

    gfunk (5th January 2007), vycke (14th February 2008)

Similar Threads

  1. Replies: 11
    Last Post: 7th July 2006, 13:09
  2. Creating Widgets
    By hylke in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2006, 08:37

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
  •  
Qt is a trademark of The Qt Company.