Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

qt widget position

Tags:

c++

position

qt

I have a main window with a grid layout and have 8 buttons in 2 rows.

 ---------------------
|                     | 
| 1     2     3     4 |
|                     | 
|                     |
| 5     6     7     8 |
|                     |
 ---------------------

I'm trying to show a popup dialog next to the button that was clicked. So, I'm trying to get the coordinates of the button in the slot connected to clicked() signal.

I have tried

QPoint p = btn->pos();

and

QPoint p = btn->geometry().topLeft();

and both are (0, 0) for some reason. How can I obtain the position of the button that was clicked in this slot?

Thanks

like image 515
Professor Chaos Avatar asked Jul 21 '12 18:07

Professor Chaos


1 Answers

I think you need to map the position of the button relative to the parent window.

QWidget::mapTo

Translates the widget coordinate pos to the coordinate system of parent. The parent must not be 0 and must be a parent of the calling widget.

like image 101
parapura rajkumar Avatar answered Oct 05 '22 22:10

parapura rajkumar