Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [Solved] Restriction when making modal mdi windows
QtWS25 Last Chance

[Solved] Restriction when making modal mdi windows

Scheduled Pinned Locked Moved General and Desktop
35 Posts 6 Posters 19.9k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    d.oberkofler
    wrote on last edited by
    #4

    Thank you for all your help!

    I'm not so sure why an MDI window should never be modal by definition (quote from Wikipedia: Graphical computer applications with a multiple document interface (MDI) are those whose windows reside under a single parent window (usually except for modal windows), as opposed to all windows being separate from each other (single document interface)) but I know that this would lead to a discussion about MDI in general and I'm just trying to get a problem solved.

    I just take it as granted that Qt does not allow to create a modal MDI window but understand that I can create a modal window/dialog as long as it is not part of the MDI area.

    I'm not fixated on using an MDI UI but what alternative design/implementation would you suggest to get the following:

    • I need a "task window" acting as an enclosure for all my application windows
    • It would be nice to keep all (actually most) application windows organized inside the "task window"
    • I need a single menu bar for my application and a open windows menu showing the open windows
    • I need to create nested hierarchies of the application windows
    • I (sometimes) need to create window modal dialogs for specific MDI windows that have a nested hierarchy
    • On the windows platform typically only the "task window" should appear in the task bar
    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #5

      [quote author="d.oberkofler" date="1294043636"]I'm not so sure why an MDI window should never be modal by definition [/quote]Whether by definition or not, it doesn't make sense at all to choose an MDI setup (where you can switch between windows without restriction) while blocking interaction with all other windows...

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #6

        Hmmm... So I guess you want to make modal dialogs that are specific to a certain MDI subwindow? I guess there may be usecases for such a thing, but it is AFAIK not supported by Qt directly. However, I think it would not be that hard to create something that would work.

        One way that might work is to create a QMdiSubWindow subclass that supports putting an overlay over the whole window (for instance a partly opaque black rectangle so your window looks unavailable) and keeps another QMdiSubWindow above itself. So, when you activate the window that has an open model dialog on top of it, it would immediately activate that window so it is put on top of it. You then make sure your MDI windows are subclasses of this new class instead of inheriting QMdiSubWindow directly.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          d.oberkofler
          wrote on last edited by
          #7

          [quote author="Franzk" date="1294046110"]
          [quote author="d.oberkofler" date="1294043636"]I'm not so sure why an MDI window should never be modal by definition [/quote]Whether by definition or not, it doesn't make sense at all to choose an MDI setup (where you can switch between windows without restriction) while blocking interaction with all other windows...
          [/quote]
          I beg to differ!
          I do have very valid use cases where windows in an MDI application have a nested hierarchy and need to block the interaction with the parent windows.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            d.oberkofler
            wrote on last edited by
            #8

            [quote author="Andre" date="1294047672"]Hmmm... So I guess you want to make modal dialogs that are specific to a certain MDI subwindow? I guess there may be usecases for such a thing, but it is AFAIK not supported by Qt directly. However, I think it would not be that hard to create something that would work.
            One way that might work is to create a QMdiSubWindow subclass that supports putting an overlay over the whole window (for instance a partly opaque black rectangle so your window looks unavailable) and keeps another QMdiSubWindow above itself. So, when you activate the window that has an open model dialog on top of it, it would immediately activate that window so it is put on top of it. You then make sure your MDI windows are subclasses of this new class instead of inheriting QMdiSubWindow directly. [/quote]

            We are currently emulating in Qt the needed behavior by disabling the parent windows. This does work but is not a very elegant solution. I wanted to explore the options Qt offers but it seems as if the restriction Qt imposes would not allow us to use modality to satisfy our requirements.

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #9

              [quote author="d.oberkofler" date="1294050480"]
              We are currently emulating in Qt the needed behavior by disabling the parent windows. This does work but is not a very elegant solution. I wanted to explore the options Qt offers but it seems as if the restriction Qt imposes would not allow us to use modality to satisfy our requirements.
              [/quote]
              I don't think it is a restriction from Qt per se, but more a restriction in the standard way this document model works. I have not seen the behaviour you're after on other platforms either, as far as I can remember. I think it makes sense that it is not provided by default, but I think it is still posible to provide it in a reasonable way. For me, that is a sensible choice: make easy what is common, and make possible what is not.

              1 Reply Last reply
              0
              • D Offline
                D Offline
                d.oberkofler
                wrote on last edited by
                #10

                [quote author="Andre" date="1294051003"]For me, that is a sensible choice: make easy what is common, and make possible what is not.[/quote]
                I agree

                1 Reply Last reply
                0
                • G Offline
                  G Offline
                  goetz
                  wrote on last edited by
                  #11

                  MDI windows per se do not have a "hierarchy" on themselves. Each QMdiSubWindow is treated equally in Qt. You can have window modal dialogs on a single MDI subwindow by calling "open() ":http://doc.trolltech.com/stable/qdialog.html#open on the dialog. The other subwindows are fully functional then. "Qt Quarterly":http://doc.trolltech.com/qq/ Issue 30 has a nice article about Dialogs and Modalities.

                  If you have a kind of hierarchy on your subwindows, and if you want to block all the windows in the hierarchy if some modal dialog is opened from one of its members, you must both set up that relationship manually and disable user interaction the windows.

                  Qt does not provide a direct way to achieve this, as this is not a common use case for MDI applications.

                  http://www.catb.org/~esr/faqs/smart-questions.html

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    d.oberkofler
                    wrote on last edited by
                    #12

                    [quote author="Volker" date="1294061799"]MDI windows per se do not have a "hierarchy" on themselves. Each QMdiSubWindow is treated equally in Qt. You can have window modal dialogs on a single MDI subwindow by calling "open() ":http://doc.trolltech.com/stable/qdialog.html#open on the dialog. The other subwindows are fully functional then. "Qt Quarterly":http://doc.trolltech.com/qq/ Issue 30 has a nice article about Dialogs and Modalities.
                    If you have a kind of hierarchy on your subwindows, and if you want to block all the windows in the hierarchy if some modal dialog is opened from one of its members, you must both set up that relationship manually and disable user interaction the windows.
                    Qt does not provide a direct way to achieve this, as this is not a common use case for MDI applications.[/quote]

                    Thank you for the additional information!
                    Now I'm again unsure if Qt might be able to solve our my use case out of the box.

                    Please let me explain in more detail what I need:

                    • There can be several open subwindows in the MDI area and interact with each other (enabling and disabling the user interaction clearly must be done manually)
                    • Sometimes one of the subwindows needs to be blocked from any user interaction because the user needs to complete a (modal) dialog before resuming to interact with the subwindow (this is where is would need a window modal dialog)

                    Can (and how) can this be done in Qt?

                    1 Reply Last reply
                    0
                    • G Offline
                      G Offline
                      giesbert
                      wrote on last edited by
                      #13

                      If it is a Dialog ( and is displayed as dialog), just create the dialog and call dlg.exec();

                      @
                      {
                      CMyDialog dlg();
                      if(QDialog::Accepted == dlg.exec())
                      {
                      // handle ok
                      }
                      else
                      {
                      // handle cancel
                      }
                      }
                      @

                      But this opens a new dialog window (not inside the MDI area) which is application modal. No other application windows can be handled, expect they are created from this dialog (as sub dialogs etc.).

                      Nokia Certified Qt Specialist.
                      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                      1 Reply Last reply
                      0
                      • A Offline
                        A Offline
                        andre
                        wrote on last edited by
                        #14

                        Gerolf, did you actually read the thread before replying? Displaying an application modal dialog box was not the issue at all.

                        1 Reply Last reply
                        0
                        • D Offline
                          D Offline
                          d.oberkofler
                          wrote on last edited by
                          #15
                          1. I do understand the availability of a stand-alone application modal dialog in an MDI application but according to [quote author="Volker" date="1294061799"]You can have window modal dialogs on a single MDI subwindow by calling "open()[/quote] it should also be possible to create a window modal dialog on a single MDI subwindow and this is where I'm still a little confused.

                          2. What's also still unclear is how to create a modal dialog with sheet style on the OSX platform for a MDI subwindow.

                          1 Reply Last reply
                          0
                          • G Offline
                            G Offline
                            giesbert
                            wrote on last edited by
                            #16

                            To 1) window modal means modal to the top level window, which is the mainWindow.
                            To 2)
                            bq. What’s also still unclear is how to create a modal dialog with sheet style on the OSX platform for a MDI subwindow.

                            do you want a dialog?

                            Nokia Certified Qt Specialist.
                            Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                            1 Reply Last reply
                            0
                            • G Offline
                              G Offline
                              giesbert
                              wrote on last edited by
                              #17

                              [quote author="Andre" date="1294134904"]Gerolf, did you actually read the thread before replying? Displaying an application modal dialog box was not the issue at all.[/quote]

                              Yes, I have. But if you read it, there is sometimes talked about modal dialogs, sometime about MDI subwindows which should be model. The second one does not work without doing it by hand --> disabling all other windows.

                              Nokia Certified Qt Specialist.
                              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                              1 Reply Last reply
                              0
                              • D Offline
                                D Offline
                                d.oberkofler
                                wrote on last edited by
                                #18

                                [quote author="Gerolf" date="1294139711"]To 1) window modal means modal to the top level window, which is the mainWindow.[/quote]In my understanding this is only the case in an MDI application.
                                Does this imply that in an MDI application there is no difference between application and window modal?
                                Would it therefore also be impossible to create a (window) modal "Sheet" for a MDI subwindow?

                                [quote author="Gerolf" date="1294139711"]To 2)
                                do you want a dialog?[/quote]Typically a QDialog (Sheet on OSX) but does it make any difference if it would "only" be a QWidget?

                                1 Reply Last reply
                                0
                                • A Offline
                                  A Offline
                                  andre
                                  wrote on last edited by
                                  #19

                                  I guess the point is, that a QMdiSubWindow - in my understanding - really isn't a window at all. It is a widget that can be moved around an a working area (another widget) and that has some decorations drawn around it to make it look like a window. That would imply that the only window that have available, is your main (task) window: the window that is visible on the systems task bar.

                                  1 Reply Last reply
                                  0
                                  • G Offline
                                    G Offline
                                    goetz
                                    wrote on last edited by
                                    #20

                                    [quote author="d.oberkofler" date="1294139506"]2) What's also still unclear is how to create a modal dialog with sheet style on the OSX platform for a MDI subwindow.
                                    [/quote]

                                    You can create a Mac sheet this way:

                                    @
                                    SheetDialog *sd = new SheetDialog((QWidget *)this->parent());
                                    sd->open();
                                    @

                                    Important is the call to open instead of exec. Qt Quarterly Issue 18 has an Introduction to "Qt/Mac Special Features":http://doc.trolltech.org/qq/qq18-macfeatures.html, including the sheets.

                                    Unfortunately you cannot have a dialog which is modal to a single MDI subwindow only, it's always modal to the hierarchy of widgets and windows, which ends with the toplevel widgets (i.e. that without a parent widget; mostly QMainWindows or QDialogs). That means, if you set up a window modal dialog the complete MDI area and all of its subwindows are blocked.

                                    http://www.catb.org/~esr/faqs/smart-questions.html

                                    1 Reply Last reply
                                    0
                                    • G Offline
                                      G Offline
                                      goetz
                                      wrote on last edited by
                                      #21

                                      [quote author="Andre" date="1294144204"]I guess the point is, that a QMdiSubWindow - in my understanding - really isn't a window at all. It is a widget that can be moved around an a working area (another widget) and that has some decorations drawn around it to make it look like a window. That would imply that the only window that have available, is your main (task) window: the window that is visible on the systems task bar. [/quote]

                                      That's right. At least it is not a toplevel window. This is the widget hierarchy of a widget that's placed in a QMdiSubWindow:

                                      @
                                      SubWindow(0x1b00060, name = "SubWindow")
                                      QMdiSubWindow(0x1b04830)
                                      QWidget(0x15a1ca40)
                                      QMdiArea(0x15a08820, name = "mdiArea")
                                      QWidget(0x15a168a0, name = "centralWidget")
                                      MainWindow(0xbffff980, name = "MainWindow")
                                      @

                                      With SubWindow being my widget, thats placed in the MDI area with mdiArea->addSubWindow(widget) and MainWindow beeing my QMainWindow subclass.

                                      http://www.catb.org/~esr/faqs/smart-questions.html

                                      1 Reply Last reply
                                      0
                                      • G Offline
                                        G Offline
                                        giesbert
                                        wrote on last edited by
                                        #22

                                        bq. d.oberkofer wrote
                                        Typically a QDialog (Sheet on OSX) but does it make any difference if it would “only” be a QWidget?

                                        If you need a dialog, there should not be a problem.

                                        Regarding window / application modal:

                                        modalness always is regarding the top level window. If you have several top level windows, you can also have application modal stuff (thats an addition in multi window applications).

                                        Nokia Certified Qt Specialist.
                                        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

                                        1 Reply Last reply
                                        0
                                        • I Offline
                                          I Offline
                                          ivan.todorovich
                                          wrote on last edited by
                                          #23

                                          I think the Qt's "Window's Modalness" features are bad implemented. I mean, why restricting modal windows only to the top level parents? I know, it's probably the 99.99% of the cases. But you must always implement the most flexible solution. In this case it would be to make a Window/Dialog modal only to its parent! (And maybe, if no parent is provided, to the whole application).

                                          o_o Sorry for my rusted english.

                                          1 Reply Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved