Results 1 to 8 of 8

Thread: how to show a new QDialog inside a mainwindow?

  1. #1

    Default how to show a new QDialog inside a mainwindow?

    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

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to show a new QDialog inside a mainwindow?

    if you did that you described then dialog had to be displayed.
    so, what is the problem? what do you want to achive?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3

    Default Re: how to show a new QDialog inside a mainwindow?

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

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to show a new QDialog inside a mainwindow?

    have you seen these classes QWorkspace or QMdiArea?
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  5. #5

    Default Re: how to show a new QDialog inside a mainwindow?

    I tried Workspace and seems work fine, I do:

    Qt Code:
    1. workspace = new QWorkspace();
    2. setCentralWidget(workspace);
    3.  
    4. MyDialog* dialog = new MyDialog(workspace);
    5. workspace->addWindow(dialog);
    6.  
    7. dialog->show();
    To copy to clipboard, switch view to plain text mode 

    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

  6. #6
    Join Date
    Dec 2008
    Location
    Isfahan (Iran)
    Posts
    6
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: how to show a new QDialog inside a mainwindow?

    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:

    Qt Code:
    1. delete dialog;
    To copy to clipboard, switch view to plain text mode 

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

  7. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: how to show a new QDialog inside a mainwindow?

    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.
    Qt Code:
    1. ...
    2. MyDialog* dialog = new MyDialog(workspace);
    3. dialog->setAttribute(Qt::WA_DeleteOnClose);
    4. ...
    To copy to clipboard, switch view to plain text mode 
    in this case the dialog will be deleted immediately after closing.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  8. #8
    Join Date
    Jul 2016
    Posts
    3
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: how to show a new QDialog inside a mainwindow?

    I show a dialog inside a dialog like this:
    Qt Code:
    1. DlgSmall.setParent(this);
    2. DlgSmall.show();
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTreeWidget row updates inside QDialog
    By innerhippy in forum Qt Programming
    Replies: 4
    Last Post: 19th December 2008, 18:32
  2. use QDialog to show file name
    By damonlin in forum Qt Programming
    Replies: 3
    Last Post: 16th November 2008, 13:52
  3. QDialog inside QWizardPage
    By baray98 in forum Qt Programming
    Replies: 1
    Last Post: 9th May 2008, 07:28
  4. QDialog, Mainwindow
    By triperzz in forum Qt Programming
    Replies: 1
    Last Post: 15th February 2008, 06:59
  5. QDialog: show() and exec() together in constructor?
    By Teuniz in forum Qt Programming
    Replies: 8
    Last Post: 28th February 2007, 11:43

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.