Results 1 to 4 of 4

Thread: Getting item absolute position

  1. #1
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting item absolute position

    Hi,

    is there any easy way (or a trick) to get the absolute position of a widget?
    I developed thinking that there was a property like this.

    Thanks,

    Nicola


    Added after 21 minutes:


    Ok .. I built it in a function

    Qt Code:
    1. function getGlobalY(startingObject)
    2. {
    3. if(assert(startingObject, "[getGlobalY] Null starting object")) return;
    4. if(isNull(startingObject.parent)) return startingObject.y;
    5. if(!isNull(startingObject.isTop) && startingObject.isTop) return startingObject.y;
    6.  
    7. var result = startingObject.y;
    8. var currentObject = startingObject.parent;
    9. while(!isNull(currentObject))
    10. {
    11. if (!isNull(currentObject.isTop) && currentObject.isTop)
    12. {
    13. // finished
    14. return result;
    15. }
    16.  
    17. if (!isNull(currentObject.y))
    18. {
    19. // adding result
    20. result += currentObject.y
    21. }
    22.  
    23. currentObject = currentObject.parent;
    24. }
    25.  
    26. printWarning("[getGlobalY] Not reached top!");
    27. return result;
    28. }
    To copy to clipboard, switch view to plain text mode 

    Note: isTop is a boolean property of my topScreen ..
    Last edited by nick85; 11th December 2013 at 15:42.

  2. #2
    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: Getting item absolute position

    What widget do you mean? A QtQuick item? There is a mapToItem() function in each item that allows to map coordinates between items.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jun 2011
    Posts
    25
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Getting item absolute position

    yes a QtQuick item.
    Ok, I can use mapToItem but function is still necessary?

  4. #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: Getting item absolute position

    What function?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. How to get item position in QTreeWidget?
    By wesley8086 in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2010, 05:28
  2. Item position in QMap?
    By lni in forum Qt Programming
    Replies: 15
    Last Post: 16th March 2009, 10:11
  3. position of an item in a QStringList
    By jaca in forum Newbie
    Replies: 4
    Last Post: 29th May 2008, 05:49
  4. How to get a position of the menu bar item?
    By Mad Max in forum Qt Programming
    Replies: 2
    Last Post: 20th November 2006, 03:20
  5. Replies: 3
    Last Post: 12th April 2006, 09:35

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.