Results 1 to 4 of 4

Thread: Modal dialog only modal to base window?

  1. #1
    Join Date
    Jul 2014
    Location
    Germany
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Modal dialog only modal to base window?

    Hello!

    I'm trying to create an multiple window application and have problems with the
    modal dialogs.

    My basic code is the following:
    Qt Code:
    1. MainWindow *mainWin = new MainWindow;
    2. mainWin->show();
    To copy to clipboard, switch view to plain text mode 
    In the MainWindow class I have the following function:
    Qt Code:
    1. void MainWindow::newWindow()
    2. {
    3. MainWindow *mainWin = new MainWindow;
    4. mainWin->show();
    5. }
    To copy to clipboard, switch view to plain text mode 
    This works fine.

    But, the modal dialogs executed from the MainWindow class (for adding/editing data)
    block any showed windows. I expected the dialogs only to block the (base) main window
    it was called from, but instead it blocked any other main windows too.

    Is this so by Qt's design or is there any way to change this behavior?

    Regards
    Sven

  2. #2
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Modal dialog only modal to base window?

    Whenever you create a QDialog, call setModality(Qt::WindowModal) to override the default behavior (Qt::ApplicationModal) which blocks all windows in the application.

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

    SvenA (9th April 2015)

  4. #3
    Join Date
    Jul 2014
    Location
    Germany
    Posts
    14
    Thanks
    3
    Qt products
    Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default [SOLVED] Re: Modal dialog only modal to base window?

    Thank you for the hint!
    I did' see this method.

    To be correct, it is this function:

    Qt Code:
    1. setWindowModality(Qt::WindowModal);
    To copy to clipboard, switch view to plain text mode 

    Regards
    Sven

  5. #4
    Join Date
    Oct 2009
    Posts
    483
    Thanked 96 Times in 93 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: [SOLVED] Re: Modal dialog only modal to base window?

    Oops, my bad. I indeed meant setWindowModality().

Similar Threads

  1. Widget over modal dialog
    By mpi in forum Qt Programming
    Replies: 3
    Last Post: 16th May 2012, 14:10
  2. Replies: 7
    Last Post: 23rd April 2011, 02:29
  3. Non-Modal about dialog?
    By N3wb in forum Qt Programming
    Replies: 1
    Last Post: 8th December 2010, 05:47
  4. QT Modal Dialog
    By jiapei100 in forum Qt Programming
    Replies: 1
    Last Post: 16th January 2010, 17:15
  5. Replies: 3
    Last Post: 1st February 2009, 15:49

Tags for this Thread

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.