cydside
11th July 2011, 15:00
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?
int findPosition(QWidget *wdg)
{
static QPoint myPos;
if (wdg->parent())
{
myPos += wdg->parent()->pos();
findPosition(wdg->parent());
}
else
return myPos;
}
Thanks in advance, Danilo
I've found a simple solution, as always happen :)
QPoint globalPos = ui->myWidget->mapToGlobal(ui->myWidget->rect().topLeft());
and it works!
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?
int findPosition(QWidget *wdg)
{
static QPoint myPos;
if (wdg->parent())
{
myPos += wdg->parent()->pos();
findPosition(wdg->parent());
}
else
return myPos;
}
Thanks in advance, Danilo
I've found a simple solution, as always happen :)
QPoint globalPos = ui->myWidget->mapToGlobal(ui->myWidget->rect().topLeft());
and it works!