Child dialog in a mail dialog.



  • 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);
    m_pChildDlg->setWindowFlags(Qt::Popup);@

    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



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

    @m_pChildDlg->setModal(true);@



  • 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



  • Are you looking for "MDI":http://developer.qt.nokia.com/doc/qt-4.7/qmdiarea.html 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



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



  • [quote author="deepak_smcet" date="1323160391"]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[/quote]

    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);
    m_pChildDlg->setWindowFlags(Qt::Popup);
    }
    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.



  • 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



  • Using a [[doc:QStackedWidget]] is really quite simple. You can do it completely using Qt Designer even, without writing code. No need to create dynamic controls.



  • @
    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.



  • 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->setWindowFlags(Qt::Widget);@

    and then call

    @ QPoint p(this->window()->geometry().topLeft());
    pChildDlg->move(p);
    pChildDlg->show();@

    the widget is not shown.

    but if i set it to
    @ 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



  • 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.



  • 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.



  • That "positional reason" is only for the initial display of the dialog.



  • I'm totally unable to understand what you are trying to achieve...



  • [quote author="fluca1978" date="1323178212"]I'm totally unable to understand what you are trying to achieve...[/quote]

    This is how I understood it:

    • there should be a non-modal toplevel window (e.g. like a search/replace window of a word processor), so that both the main window and the popup are functional at the same time
    • the second window is supposed to move together with the main window in case the latter is moved

    The problem was that by using the wrong window flags, the popup was closed when clicking into the main window.



  • [quote author="fluca1978" date="1323178212"]I'm totally unable to understand what you are trying to achieve...[/quote]

    Hence the request to send a sketch that we can look at...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.