Results 1 to 14 of 14

Thread: how to get globalPos()

  1. #1
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default how to get globalPos()

    hi friends,
    how to get the globalPos() of a particular widget in a qt application withoout using mouseEvent() ....

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get globalPos()

    use QCursor:: pos().
    PS. sorry, f*****g smiles.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how to get globalPos()

    ...or
    Qt Code:
    1. QPoint p = somewidget.mapToGlobal(QPoint(0, 0));
    To copy to clipboard, switch view to plain text mode 

  4. The following user says thank you to Lykurg for this useful post:

    wagmare (26th March 2009)

  5. #4
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get globalPos()

    Quote Originally Posted by spirit View Post
    use QCursor:: pos().
    PS. sorry, f*****g smiles.
    thanks for reply ... i am sorry to mention this ... i am developing a qapp where
    i want to check communication status every 5 sec .. if the communication fails i want to show a balloon message telling "communication failed" over a pushButton ...
    so i need the globalPos of the pushButton but i cant use QMouseEvent or cursor ...

    on creating the pushButton i want to send this position to the qtooltip constuctor .. so that i can set the tooltip to that position ....

  6. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get globalPos()

    as Lykurg said you can use this
    Qt Code:
    1. QPoint p = somewidget.mapToGlobal(button->rect().topLeft());
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  7. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how to get globalPos()

    Qt Code:
    1. QPoint p = button->mapToGlobal(QPoint(0, 0));
    To copy to clipboard, switch view to plain text mode 

    As QWidget::rect().topLeft() is allways QPoint(0, 0) which one is faster/better? Yes I know it's a stupid question, because this optimization won't make your app faster, but academically I'm interested in...

  8. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to get globalPos()

    Quote Originally Posted by Lykurg View Post
    Qt Code:
    1. QPoint p = button->mapToGlobal(QPoint(0, 0));
    To copy to clipboard, switch view to plain text mode 

    As QWidget::rect().topLeft() is allways QPoint(0, 0) which one is faster/better? Yes I know it's a stupid question, because this optimization won't make your app faster, but academically I'm interested in...
    agree, I used this as example, you can use bottomRight() for example or center().
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  9. #8
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how to get globalPos()

    Yepp, and after a look through assistant I realized that topLeft etc gives no reference back, so in the specific case QPoint(x,y) is faster/better.

  10. #9
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get globalPos()

    thank you .. i will follow the same ..

  11. #10
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get globalPos()

    Quote Originally Posted by Lykurg View Post
    Yepp, and after a look through assistant I realized that topLeft etc gives no reference back, so in the specific case QPoint(x,y) is faster/better.
    Qt Code:
    1. static int dynamite = 2;
    2. QString test = "The communication failed due to heavy rain networ all jammed \n and the enemy is attacking ... no no ";
    3.  
    4.  
    5. qreal x = value.x();
    6. qreal y = value.y();
    7.  
    8. QPoint value2 (x + 20, y -35);
    9.  
    10. if(dynamite == 2){
    11. QToolTip::showText(value2, test);
    12. if(QToolTip::isVisible () == TRUE){
    13. printf("it is visible in this area \n");
    14. }
    15. dynamite = 1;
    16. }else if(dynamite == 1){
    17. QToolTip::hideText();
    18. dynamite = 2;
    19. if(QToolTip::isVisible () == TRUE){
    20. printf("it is visible in this area \n");
    21. }
    22. }
    To copy to clipboard, switch view to plain text mode 

    i tried
    value = diagnosButton->mapToGlobal(QPoint(0,0));
    instead of value = diagnosButton->mapToGlobal(diagnosButton->rect().topLeft());
    and its not working ... only widget->rect().topLeft()); is working perfectly in this code ...

  12. #11
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get globalPos()

    when u use this:

    Qt Code:
    1. value = diagnosButton->mapToGlobal(QPoint(0,0));
    To copy to clipboard, switch view to plain text mode 

    how far from the button does the tooltip show or it doesnt show at all?

  13. #12
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get globalPos()

    Quote Originally Posted by talk2amulya View Post
    when u use this:

    Qt Code:
    1. value = diagnosButton->mapToGlobal(QPoint(0,0));
    To copy to clipboard, switch view to plain text mode 

    how far from the button does the tooltip show or it doesnt show at all?
    thanks for reply ..
    the assistant tells
    "Translates the widget coordinate pos to global screen coordinates. For example, mapToGlobal(QPoint(0,0)) would give the global coordinates of the top-left pixel of the widget."
    so i thought by default it will give the global pos of the button ...so i try to show the tooltip just above the coordinates ...

  14. #13
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get globalPos()

    no, i mean when u use QPoint(0,0), what does it do..does it show the tooltip at a wrong place or it doesnt show anything?

  15. #14
    Join Date
    Sep 2008
    Location
    Bangalore
    Posts
    659
    Thanks
    116
    Thanked 42 Times in 41 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: how to get globalPos()

    Quote Originally Posted by talk2amulya View Post
    no, i mean when u use QPoint(0,0), what does it do..does it show the tooltip at a wrong place or it doesnt show anything?
    no its not showing any tooltip if i use QPoint(0,0) ;

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.