PDA

View Full Version : ParentWidget gives me alwasy the mainwindow widget ....



tonnot
6th March 2012, 21:27
Hello everybody:
I have a few widgets placed into different containers (Qframes and Qwidgets). I have them at mainwindow level and a Qdialog level
In example :
Mainwindow->centralwidget->frame1->frame2->my_widget1;
Dialog->frame1->frame2->my_widget2;
Ok I have this code to find the top owner:


QWidget * W_qtutil::w_tell_me_the_topwidget(QWidget *widget)
{
if (widget->parentWidget()!=0)
{ QWidget * top_p = widget;
while (top_p->parentWidget()!=0)
{ top_p = top_p->parentWidget(); } // HERE
return top_p;
}
else
{
return widget;
}
}
(Still the code is not finished, I have to control when I reach a Window widget).

Ok, I have a problem, at the line marked by 'HERE' , top_p = top_p->parentWidget(); at the first excecution I have the "Ui_main" of my application, regardless of the original mainwindow or dialog where I have the widget.

That is , I 'd have to get:
frame2, frame1, centralwidget,mainwindow for my_widget1;
and
frame2. frame1, dialog for my_widget2;

But I always get Ui_main at the first time.
Any idea ? Thanks.

wysota
6th March 2012, 22:00
Hmm... what's wrong with QWidget::window()?

tonnot
7th March 2012, 07:47
Ups. You're right.