Results 1 to 6 of 6

Thread: Reparenting QDialog

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Question Reparenting QDialog

    Hello
    I'am using Qt 4.5.2
    I have specific situation in which I need first to create dialog with parent=0, and then reparent it before showing it.
    The following doesn't work, i.e the dialog is never shown :
    Qt Code:
    1. MyDialog* dlg=new MyDialog(0);
    2. dlg->setParent(some_other_dlg_ptr);
    3. dlg->show();
    To copy to clipboard, switch view to plain text mode 

    Is this supposed to work ? The documentation for QDialog says that it should work, unless I am missing something :
    "Use the overload of the QWidget::setParent() function to change the ownership of a QDialog widget."
    Thank you
    Last edited by elizabeth.h1; 9th February 2010 at 12:34.

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Reparenting QDialog

    for it to show its parent needs to be visible as well.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. The following user says thank you to high_flyer for this useful post:

    elizabeth.h1 (9th February 2010)

  4. #3
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default Re: Reparenting QDialog

    Ok, I just made a simple example to check this, and it does not work

    Qt Code:
    1. int main(int argc, char *argv[])
    2. {
    3. //dlg1 is shown
    4. QApplication app(argc, argv);
    5. GoDlg* dlg=new GoDlg;
    6. dlg->show();
    7.  
    8. // dlg2 is not shown
    9. GoDlg* dlg2=new GoDlg(0);
    10. dlg2->setParent(dlg);
    11. dlg2->show();
    12.  
    13. /*
    14.   // dlg2 is shown when parent is given in constructor
    15.   GoDlg* dlg2=new GoDlg(dlg);
    16.   dlg2->show();
    17.   */
    18. app.exec();
    19. }
    To copy to clipboard, switch view to plain text mode 

  5. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Reparenting QDialog

    Are you sure it doesn't work?
    I ask, since you have two dialogs, and if they both are a QDialog, then they are both top level widgets.
    Now, since both have the same size and looks, and the second will appear on top of the first, it is possible that you see the second, and not the first, which is under it.
    Try your example again, and move the dialog you see, and see if there is another one under it.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  6. #5
    Join Date
    Jul 2009
    Posts
    40
    Thanks
    7

    Default Re: Reparenting QDialog

    Yes, I'm sure. I drag the dialogs, and I am sure that is one dialog.
    When I uncomment the code in lines 15 and 16 ( where the parent is given in constructor ) than are two of them.
    Can anybody reproduce this behavior ?

  7. #6
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Reparenting QDialog

    Hmm...
    Looks like its a known issue, or at least was a known issue.
    http://bugreports.qt.nokia.com/browse/QTBUG-10
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  8. The following user says thank you to high_flyer for this useful post:

    elizabeth.h1 (10th February 2010)

Similar Threads

  1. Reparenting
    By brcain in forum Qt Tools
    Replies: 15
    Last Post: 5th September 2020, 18:41
  2. closing a Qdialog called from a Qdialog
    By OverTheOCean in forum Qt Programming
    Replies: 3
    Last Post: 28th September 2009, 08:02
  3. Reparenting widget to Win32 application
    By RThaden in forum Qt Programming
    Replies: 0
    Last Post: 23rd February 2009, 18:21
  4. problem: reparenting qtreewidget items in QT4
    By uglykid in forum Qt Programming
    Replies: 2
    Last Post: 21st November 2007, 16:55
  5. Reparenting a QObject
    By ghorwin in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2007, 17:21

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
  •  
Qt is a trademark of The Qt Company.