I want to get the absolute x and y coordinates of a frame control. I know that there is a QWidget::mapToGlobal
function that should give me these coordinates - but it always returns the relative points.
My code is:
int y = ui->frame->mapToGlobal(ui->frame->window()->pos()).y();
Can anyone please help me to understand what I am doing wrong?
EDIT: Found the problem - I've called this line in the main window class, before it is displayed. So now my Q is how can I get the position that the main window will be displayd in its constructor?
I think you can't, not reliably and portably anyway. The position is not decided yet, and decision is often made by window manager, not the application.
So, what you should do is override moveEvent()
, resizeEvent()
and/or showEvent()
Those are the right place to do stuff like that, instead of constructor.