child dialog in a mail dialog.
Page |
1 |
hello,
i am trying to create a child dialog in a main dialog. i am able to see and move it to main dialog geometry. using following code.
In main constructor:
- m_pChildDlg = new ClildDialog(this);
- m_pChildDlg->setModal(false);
In the button handler
- void MainDialog::DisplayDialog()
- {
- m_pChildDlg->show();
- m_QPoint p(this->window()->geometry().topLeft());
- m_pChildDlg->move(p);
- }
but when i click on the parent dialog, it disapears. i have to click on displaydialog button to show it again. what i want to achieve is i could display multiple child dialogs one at time when i click button on mail dialog.
could someone tell me how to do it?
regards
D
18 replies
Are you looking for MDI [developer.qt.nokia.com] per chance?
thanks fluca1978,but i don’t want to make it modal. what i want is to stick this dialog with main dialog. just like button, label does. a child stick to maindialog which i could hide and unhide.
regards
D
So you need a singleton dialog. What you have to do is something like this:
- if( m_pChildDlg == NULL ){
- m_pChildDlg = new ClildDialog(this);
- m_pChildDlg->setModal(false);
- }
- else
- m_pChildDlg->setVisible( true );
of course the pointer must be initialized to NULL at the beginning. So in this way you will make a single instance of the window available during the program, which is created the first time it is needed and is simply re-shown when called back again. There are other techniques to make singleton in a more elegant way, but this should suffice.
hello,
i am sorry if i am not able to communicate my question to you clearly. but thanks for you input.
there is a example here “I:\Qt\4.7.4\examples\dialogs\configdialog”. it makes use of QListWidget and QStackedWidget class. in the same way i want to have few buttons in the left side. and when i click on the different button i should display a different dialog(but the dialog should be embedded into the mail dialog just like in the example). the example make user of Qwidget class to create some demo pages.
since i am from MFC backgroud, all you have to do is to create the modalless dialog on Oninitiazedlg() and set the parent to the parent dialog. and then child dialog will be shown into the main dialog.
is there any way to upload a few kb source?
here is the MFC source:
- BOOL CChildDialogDlg::OnInitDialog()
- {
- CDialog::OnInitDialog();
- m_child.Create(CChildOne::IDD, this);
- }
- void CChildDialogDlg::OnBnClickedStShow()
- {
- // TODO: Add your control notification handler code here
- static bool bShow = true;
- if(bShow)
- m_child.ShowWindow(SW_SHOW);
- else
- m_child.ShowWindow(SW_HIDE);
- bShow = !bShow;
- }
the property is set to ‘child’ in the dialog editor of MFC.
regards
D
So you are not searching to display a dialog window, you are trying to display different widgets depending on the user selection on the left panel bar. There are different ways to achieve it, one it could be to use a stack layout. As you mentioned, take the config dialog example and implement it in a similar way. Just create a set of top level widgets that are containers for your right side widgets and display the top level containers when needed.
Using a QStackedWidget is really quite simple. You can do it completely using Qt Designer even, without writing code. No need to create dynamic controls.
hello volker,
you are right but it did not solve the problem,
if i set it to
- pChildDlg = new ClildDialog(this);
- pChildDlg->setModal(false);
- pChildDlg->move(p);
- pChildDlg->show();
is there any way to upload small source file here in the post, i dont see such option
@Andre,
i will try your suggestion soon and update the post soon
regards
D
humm,
i just a read a post here
http://lists.trolltech.com/qt-interest/2002-12/msg01080.html
which says that
“Dialogs are ALWAYS toplevel widgets and are NEVER children of other widgets. If you specify a parent in a dialog it is only for positional reasions”
i think this is my mistake, i am trying to use a dialog as a widget. i mean i am trying to make it children of other dialog.
You must log in to post a reply. Not a member yet? Register here!


