PDA

View Full Version : Reparenting QDialog



elizabeth.h1
9th February 2010, 10:55
Hello
I'am using Qt 4.5.2
I have specific situation in which I need first to create dialog with parent=0, and then reparent it before showing it.
The following doesn't work, i.e the dialog is never shown :


MyDialog* dlg=new MyDialog(0);
dlg->setParent(some_other_dlg_ptr);
dlg->show();


Is this supposed to work ? The documentation for QDialog says that it should work, unless I am missing something :
"Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget."
Thank you

high_flyer
9th February 2010, 10:57
for it to show its parent needs to be visible as well.

elizabeth.h1
9th February 2010, 11:28
Ok, I just made a simple example to check this, and it does not work :(



int main(int argc, char *argv[])
{
//dlg1 is shown
QApplication app(argc, argv);
GoDlg* dlg=new GoDlg;
dlg->show();

// dlg2 is not shown
GoDlg* dlg2=new GoDlg(0);
dlg2->setParent(dlg);
dlg2->show();

/*
// dlg2 is shown when parent is given in constructor
GoDlg* dlg2=new GoDlg(dlg);
dlg2->show();
*/
app.exec();
}

high_flyer
9th February 2010, 16:58
Are you sure it doesn't work?
I ask, since you have two dialogs, and if they both are a QDialog, then they are both top level widgets.
Now, since both have the same size and looks, and the second will appear on top of the first, it is possible that you see the second, and not the first, which is under it.
Try your example again, and move the dialog you see, and see if there is another one under it.

elizabeth.h1
9th February 2010, 20:20
Yes, I'm sure. I drag the dialogs, and I am sure that is one dialog.
When I uncomment the code in lines 15 and 16 ( where the parent is given in constructor ) than are two of them.
Can anybody reproduce this behavior ?

high_flyer
10th February 2010, 08:47
Hmm...
Looks like its a known issue, or at least was a known issue.
http://bugreports.qt.nokia.com/browse/QTBUG-10