PDA

View Full Version : how to get globalPos()



wagmare
26th March 2009, 12:15
hi friends,
how to get the globalPos() of a particular widget in a qt application withoout using mouseEvent() ....

spirit
26th March 2009, 12:16
use QCursor:: pos().
PS. sorry, f*****g smiles. :)

Lykurg
26th March 2009, 12:26
...or
QPoint p = somewidget.mapToGlobal(QPoint(0, 0));

wagmare
26th March 2009, 12:27
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 ....

spirit
26th March 2009, 12:29
as Lykurg said you can use this


QPoint p = somewidget.mapToGlobal(button->rect().topLeft());

Lykurg
26th March 2009, 12:35
QPoint p = button->mapToGlobal(QPoint(0, 0));


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...

spirit
26th March 2009, 12:41
QPoint p = button->mapToGlobal(QPoint(0, 0));


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().

Lykurg
26th March 2009, 12:45
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.

wagmare
26th March 2009, 12:55
thank you .. i will follow the same ..

wagmare
30th March 2009, 10:58
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.



static int dynamite = 2;
QString test = "The communication failed due to heavy rain networ all jammed \n and the enemy is attacking ... no no ";


qreal x = value.x();
qreal y = value.y();

QPoint value2 (x + 20, y -35);

if(dynamite == 2){
QToolTip::showText(value2, test);
if(QToolTip::isVisible () == TRUE){
printf("it is visible in this area \n");
}
dynamite = 1;
}else if(dynamite == 1){
QToolTip::hideText();
dynamite = 2;
if(QToolTip::isVisible () == TRUE){
printf("it is visible in this area \n");
}
}


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 ...

talk2amulya
30th March 2009, 11:05
when u use this:


value = diagnosButton->mapToGlobal(QPoint(0,0));

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

wagmare
30th March 2009, 12:44
when u use this:


value = diagnosButton->mapToGlobal(QPoint(0,0));

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 ...

talk2amulya
30th March 2009, 13:16
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?

wagmare
30th March 2009, 13:50
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) ;