December 6, 2011

deepak_smcet deepak_smcet
Lab Rat
12 posts

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:

  1. m_pChildDlg = new ClildDialog(this);
  2. m_pChildDlg->setModal(false);
  3. m_pChildDlg->setWindowFlags(Qt::Popup);

In the button handler

  1. void MainDialog::DisplayDialog()
  2. {
  3.      m_pChildDlg->show();
  4.      m_QPoint p(this->window()->geometry().topLeft());
  5.      m_pChildDlg->move(p);
  6. }

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

December 6, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

If you want to display one dialog at a time you have to do:

  1. m_pChildDlg->setModal(true);

December 6, 2011

McgowanM McgowanM
Lab Rat
1 posts

m_pChildDlg->setModal(false)

I’m extremely sorry, but I don’t get this.
Is it because I’m a grown up? Or it’s because I’m not smart enough? :D

 Signature 

mkv player

December 6, 2011

Andre Andre
Area 51 Engineer
6031 posts

Are you looking for MDI [developer.qt.nokia.com] per chance?

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

December 6, 2011

deepak_smcet deepak_smcet
Lab Rat
12 posts

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

December 6, 2011

Andre Andre
Area 51 Engineer
6031 posts

Could you perhaps post a sketch of what you want to achieve?

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

December 6, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

deepak_smcet wrote:
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:

  1. if( m_pChildDlg == NULL ){
  2.  m_pChildDlg = new ClildDialog(this);
  3.  m_pChildDlg->setModal(false);
  4.  m_pChildDlg->setWindowFlags(Qt::Popup);
  5. }
  6. else
  7.    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.

December 6, 2011

deepak_smcet deepak_smcet
Lab Rat
12 posts

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:

  1. BOOL CChildDialogDlg::OnInitDialog()
  2. {
  3.  CDialog::OnInitDialog();
  4.  
  5.  m_child.Create(CChildOne::IDD, this);
  6. }
  7.  
  8. void CChildDialogDlg::OnBnClickedStShow()
  9. {
  10.  // TODO: Add your control notification handler code here
  11.  static bool bShow = true;
  12.  
  13.  
  14.  if(bShow)
  15.   m_child.ShowWindow(SW_SHOW);
  16.  else
  17.   m_child.ShowWindow(SW_HIDE);
  18.  
  19.  bShow = !bShow;
  20.  
  21. }

the property is set to ‘child’ in the dialog editor of MFC.

regards
D

December 6, 2011

fluca1978 fluca1978
Ant Farmer
524 posts

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.

December 6, 2011

deepak_smcet deepak_smcet
Lab Rat
12 posts

is there any other way to do it except using stacked containers? any simpler way? the reason i am using dialog is because i could make use to editor to place other items on it. but in the example, all the other controls are created dynamically.

regards
D

December 6, 2011

Andre Andre
Area 51 Engineer
6031 posts

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.

 Signature 

Looking for Qt developers to join our team @ i-Optics: https://qt-project.org/forums/viewthread/25393/

December 6, 2011

Volker Volker
Robot Herder
5428 posts

  1. m_pChildDlg->setWindowFlags(Qt::Popup);

is most likely to cause your trouble. Popups usually go away when they loos focus (what happens by clicking the main window). Just make it a regular window/widget and you’re done.

December 6, 2011

deepak_smcet deepak_smcet
Lab Rat
12 posts

hello volker,

you are right but it did not solve the problem,

if i set it to

  1. pChildDlg = new ClildDialog(this);
  2.  pChildDlg->setModal(false);
  3.  pChildDlg->setWindowFlags(Qt::Widget);

and then call
  1.  QPoint p(this->window()->geometry().topLeft());
  2.   pChildDlg->move(p);
  3.   pChildDlg->show();
the widget is not shown. but if i set it to
  1.   pChildDlg->setWindowFlags(Qt::Window);
the dialog is shown but has border on it, i used the property ‘WindowTitleHint’ to clear some of those. yes after setting above flag it does not go away, but when i move the main window it does not move with it. i want it to be stick to main window just like button and other dialogs.

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

December 6, 2011

Volker Volker
Robot Herder
5428 posts

You have a completely independent window with your popup. To move it together with your mainwindow, you need to reimplement moveEvent and move your popup by the same amount as your mainwindow.

December 6, 2011

deepak_smcet deepak_smcet
Lab Rat
12 posts

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.

December 6, 2011

Volker Volker
Robot Herder
5428 posts

That “positional reason” is only for the initial display of the dialog.

Page  
1

  ‹‹ Generating XML in Qt      [Solved]Swedish sp letters ››

You must log in to post a reply. Not a member yet? Register here!