PDA

View Full Version : how to show a new QDialog inside a mainwindow?



cram07
3rd January 2009, 13:21
Hello,

I am just a really newbie in QT, and now I am blocked trying to do that. I just want open or show a new QDialog inside the MainWindow ...

I open mydialog at this way:
MyDialog dialog(this);
dialog.exec();

and this just open a new window separated of the MainWindow. I don't know if I explained it ok, as my skills of qt my skills of english aren't really good..

thanks

spirit
3rd January 2009, 13:26
if you did that you described then dialog had to be displayed.
so, what is the problem? what do you want to achive?

cram07
3rd January 2009, 13:49
yes, the dialog is displayed. But it is displayed free, I would like enclose this dialog in the mainwindow.., i know exists a word for describe that but I don't know (maybe docked??, i don't know)

at this way the dialog can be moved and maximized freely inside the all the system screen, and I don't want that, I want enclose the dialog in the frames of the mainwindow..

spirit
3rd January 2009, 13:53
have you seen these classes QWorkspace or QMdiArea?

cram07
3rd January 2009, 16:14
I tried Workspace and seems work fine, I do:



workspace = new QWorkspace();
setCentralWidget(workspace);

MyDialog* dialog = new MyDialog(workspace);
workspace->addWindow(dialog);

dialog->show();


but now I have another little question, now when the dialog is closed the function ~MyDialog is not throwed until the mainwindow is closed. What does it means?? the Dialog still consuming memory until the mainwindows is closed??

thanks

golnaz
3rd January 2009, 16:35
yes, because you have defined dialog using a pointer an new() operator. so the dialog exists in memory as long as its parent exists.
if you need to destruct dialog sooner, do this:


delete dialog;

by calling delete operator, ~MyDialog will be called, then dialog will be cleared from memory. :)

spirit
3rd January 2009, 16:36
that's right because you pass parent to dialog if you do not do this then you have to delete the dialog using delete operator of course if you allocated dialog in the heap. another way it's to use Qt::WA_DeleteOnClose widget attribute.


...
MyDialog* dialog = new MyDialog(workspace);
dialog->setAttribute(Qt::WA_DeleteOnClose);
...

in this case the dialog will be deleted immediately after closing.

sunny127
25th July 2016, 14:42
I show a dialog inside a dialog like this:


DlgSmall.setParent(this);
DlgSmall.show();