Hi to all,
I'm looking for a method to calculate a widget position nested in an unknown structure of parent widgets. Should I use a recursive function like the follow pseudo-code?
{
if (wdg->parent())
{
myPos += wdg->parent()->pos();
findPosition(wdg->parent());
}
else
return myPos;
}
int findPosition(QWidget *wdg)
{
static QPoint myPos;
if (wdg->parent())
{
myPos += wdg->parent()->pos();
findPosition(wdg->parent());
}
else
return myPos;
}
To copy to clipboard, switch view to plain text mode
Thanks in advance, Danilo
I've found a simple solution, as always happen ![Smile](images/smilies/smile.png)
QPoint globalPos
= ui
->myWidget
->mapToGlobal
(ui
->myWidget
->rect
().
topLeft());
QPoint globalPos = ui->myWidget->mapToGlobal(ui->myWidget->rect().topLeft());
To copy to clipboard, switch view to plain text mode
and it works!
Bookmarks