5
votes

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

1

1 Answers

8
votes

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.