Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Recommended Approach for Inline Modal
Qt 6.12 LTS is out! See what's new in the release blog

[SOLVED] Recommended Approach for Inline Modal

Scheduled Pinned Locked Moved General and Desktop
15 Posts 2 Posters 5.0k Views 2 Watching
  • 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.
  • M maximo

    I'd like to make an inline modal dialog (flat interface style) on top of my centralWidget of my main application window. However, if I do this, I then can't see and work with my other widgets on the page unless I move that thing out of the way all the time in the designer. This dialog needs to show an opaque, dark dimmer, and then show a dialog on top of that with widgets particular my need. In fact, I may have 4-5 of these, each with unusable, separate purposes.

    I'd rather not draw that entire form in code -- I'd rather do it in the designer.

    Is there a way that I can draw a separate Qt form, and then programmatically apply that form on top my existing centralWidget of my main application window? I don't mean as a window with its own titlebar and all that -- I mean a window that's inline (sort of like a web page).

    I was thinking that I could use ui->centralWidget->setParent(w) and that w would be the widgets from the other form. I just don't know how to hook that up, or if its even possible.

    mrjjM Offline
    mrjjM Offline
    mrjj
    Lifetime Qt Champion
    wrote on last edited by mrjj
    #2

    @maximo
    Hi
    Im not 100% sure the exact effect you want
    so I will just suggest some stuff. bare with me :)
    the
    setWindowFlags ( Qt::FramelessWindowHint );
    (in dialogs constructor)
    can be used to make the dialog completely without decorations
    as borders/caption etc. At run time you can then
    just exec() it and it can pop up over central widget.

    If you really want it truly inline
    you could use the promote feature
    but it would not really be a dialog anymore.

    If you add a new dialog via New->Qt->Designer->Dialog
    and add stuff to its UI file in Creator.
    Lets call it mydialog

    Then if you add a widget to the centralWidget. Right click
    and select promote and then tell
    mydialog.h and press add + promote.
    (check spelling as it does not)

    When you then start the program, the content from mydialog UI would then be in that widget.
    But that would be Inside centralWidget, not over it.

    M 1 Reply Last reply
    0
    • mrjjM mrjj

      @maximo
      Hi
      Im not 100% sure the exact effect you want
      so I will just suggest some stuff. bare with me :)
      the
      setWindowFlags ( Qt::FramelessWindowHint );
      (in dialogs constructor)
      can be used to make the dialog completely without decorations
      as borders/caption etc. At run time you can then
      just exec() it and it can pop up over central widget.

      If you really want it truly inline
      you could use the promote feature
      but it would not really be a dialog anymore.

      If you add a new dialog via New->Qt->Designer->Dialog
      and add stuff to its UI file in Creator.
      Lets call it mydialog

      Then if you add a widget to the centralWidget. Right click
      and select promote and then tell
      mydialog.h and press add + promote.
      (check spelling as it does not)

      When you then start the program, the content from mydialog UI would then be in that widget.
      But that would be Inside centralWidget, not over it.

      M Offline
      M Offline
      maximo
      wrote on last edited by
      #3

      @mrjj I tried to follow your instructions in Qt5.5 Creator but they didn't line up.

      mrjjM 1 Reply Last reply
      0
      • M maximo

        @mrjj I tried to follow your instructions in Qt5.5 Creator but they didn't line up.

        mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #4

        @maximo
        what did not line up?
        The dialogs?
        Did you inline it or use frameless dialogs?

        M 1 Reply Last reply
        0
        • mrjjM mrjj

          @maximo
          what did not line up?
          The dialogs?
          Did you inline it or use frameless dialogs?

          M Offline
          M Offline
          maximo
          wrote on last edited by
          #5

          @mrjj

          1. New > QT Designer > Dialog. Doesn't exist. Did you mean Designer Form or Designer Form Class?

          2. Add stuff to the new dialog.

          3. Add a widget to the centralWidget. Which centralWidget? The one in the main application window (I assume) ? Also, you say "add a widget". Did you mean just the widget in the toolbox that says "Widget"?

          4. Rightclick the centralWidget and choose Promote. I did this in the main window. I see a dialog that looks like this:

          http://screencast.com/t/9xLRr59xgTzM

          I have no clue what to put in those fields.

          mrjjM 1 Reply Last reply
          0
          • M maximo

            @mrjj

            1. New > QT Designer > Dialog. Doesn't exist. Did you mean Designer Form or Designer Form Class?

            2. Add stuff to the new dialog.

            3. Add a widget to the centralWidget. Which centralWidget? The one in the main application window (I assume) ? Also, you say "add a widget". Did you mean just the widget in the toolbox that says "Widget"?

            4. Rightclick the centralWidget and choose Promote. I did this in the main window. I see a dialog that looks like this:

            http://screencast.com/t/9xLRr59xgTzM

            I have no clue what to put in those fields.

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #6

            @maximo

            1. Sorry . didn't write all steps.
              Yes its Designer Form Class, then choose Dialog in center.

            2. The edit controls or what you want to be displayed in the mainform in your inline dialog. buttons and such.

            3. The mainwindow centralWidget. yes. I assumed you wanted it there.
              Yes, "Add widget" is that widget type from the list.
              It is just a place holder. Could also use Frame.

            in

            Promoted class name,

            we must type the name of the dialog class.
            Like
            MyDialog
            or whatever you call it in (1).
            Note big/small letters.
            Then in

            Headerfile

            you must type name of header file.
            like
            mydialog.h
            (this is most likely small letters)

            Then Press Add button
            and now you can press the Promote button.

            Hope this is better to follow.

            M 1 Reply Last reply
            0
            • mrjjM mrjj

              @maximo

              1. Sorry . didn't write all steps.
                Yes its Designer Form Class, then choose Dialog in center.

              2. The edit controls or what you want to be displayed in the mainform in your inline dialog. buttons and such.

              3. The mainwindow centralWidget. yes. I assumed you wanted it there.
                Yes, "Add widget" is that widget type from the list.
                It is just a place holder. Could also use Frame.

              in

              Promoted class name,

              we must type the name of the dialog class.
              Like
              MyDialog
              or whatever you call it in (1).
              Note big/small letters.
              Then in

              Headerfile

              you must type name of header file.
              like
              mydialog.h
              (this is most likely small letters)

              Then Press Add button
              and now you can press the Promote button.

              Hope this is better to follow.

              M Offline
              M Offline
              maximo
              wrote on last edited by
              #7

              @mrjj Okay, I added it (called it "Dialog") and this is what that form looks like:

              http://screencast.com/t/KVtqWZfCHE

              However, when I do Build > Run from the menus, I don't see the QWidget with that UI inside it. I don't see the QWidget at all.

              What do I do next?

              mrjjM 1 Reply Last reply
              0
              • M maximo

                @mrjj Okay, I added it (called it "Dialog") and this is what that form looks like:

                http://screencast.com/t/KVtqWZfCHE

                However, when I do Build > Run from the menus, I don't see the QWidget with that UI inside it. I don't see the QWidget at all.

                What do I do next?

                mrjjM Offline
                mrjjM Offline
                mrjj
                Lifetime Qt Champion
                wrote on last edited by mrjj
                #8

                Hi
                And you have promoted a widget or frame ?
                After you added it. You must press Promote.
                So you must right click the widget (placeholder) and promote it to Dialog.
                Did you do that besides adding it ?

                And you did add something to the ui file (for Dialog) ?
                (so there is something to show up ?)

                Update:
                Ok it looks like you did it right.

                So how do you mainscreen look like before you run it ?

                mrjjM 1 Reply Last reply
                0
                • mrjjM mrjj

                  Hi
                  And you have promoted a widget or frame ?
                  After you added it. You must press Promote.
                  So you must right click the widget (placeholder) and promote it to Dialog.
                  Did you do that besides adding it ?

                  And you did add something to the ui file (for Dialog) ?
                  (so there is something to show up ?)

                  Update:
                  Ok it looks like you did it right.

                  So how do you mainscreen look like before you run it ?

                  mrjjM Offline
                  mrjjM Offline
                  mrjj
                  Lifetime Qt Champion
                  wrote on last edited by mrjj
                  #9

                  Ok. sorry. I remembered wrong.
                  Select Type "Widget" in step 1.
                  Not Dialog.

                  Default name will be Form
                  so put
                  Form
                  and
                  form.h
                  in promote dialog,
                  and "add" and "promote"
                  Just made small test here to be sure.
                  https://www.dropbox.com/s/p69tpbmi9v059b4/maxtest.zip?dl=0

                  M 1 Reply Last reply
                  0
                  • mrjjM mrjj

                    Ok. sorry. I remembered wrong.
                    Select Type "Widget" in step 1.
                    Not Dialog.

                    Default name will be Form
                    so put
                    Form
                    and
                    form.h
                    in promote dialog,
                    and "add" and "promote"
                    Just made small test here to be sure.
                    https://www.dropbox.com/s/p69tpbmi9v059b4/maxtest.zip?dl=0

                    M Offline
                    M Offline
                    maximo
                    wrote on last edited by
                    #10

                    @mrjj Worked! Awesome!

                    mrjjM 1 Reply Last reply
                    0
                    • M maximo

                      @mrjj Worked! Awesome!

                      mrjjM Offline
                      mrjjM Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      @maximo
                      Super :) sorry for the confusion.
                      I hope its what you wanted.

                      M 2 Replies Last reply
                      1
                      • mrjjM mrjj

                        @maximo
                        Super :) sorry for the confusion.
                        I hope its what you wanted.

                        M Offline
                        M Offline
                        maximo
                        wrote on last edited by
                        #12

                        @mrjj It is, exactly. I guess the only thing I want to know now is how to promote via code. That way, I can stick one widget on the Main Window's centralWidget and then just switch the promotions via code.

                        M 1 Reply Last reply
                        0
                        • M maximo

                          @mrjj It is, exactly. I guess the only thing I want to know now is how to promote via code. That way, I can stick one widget on the Main Window's centralWidget and then just switch the promotions via code.

                          M Offline
                          M Offline
                          maximo
                          wrote on last edited by maximo
                          #13

                          @mrjj It doesn't look like there's a programmatic way to do that unless I want to do something messy like intercept the Paint event:

                          http://stackoverflow.com/questions/32584320/programmatically-promote-qwidget

                          So, what I'll do is use a QStackedWidget control and put my content inside that. That way, I can put several dialogs there that I can flip in the designer, and then switch that index via code.

                          1 Reply Last reply
                          0
                          • mrjjM mrjj

                            @maximo
                            Super :) sorry for the confusion.
                            I hope its what you wanted.

                            M Offline
                            M Offline
                            maximo
                            wrote on last edited by
                            #14

                            @mrjj I tidied this up here:

                            http://stackoverflow.com/a/32940561/105539

                            1 Reply Last reply
                            1
                            • mrjjM Offline
                              mrjjM Offline
                              mrjj
                              Lifetime Qt Champion
                              wrote on last edited by
                              #15

                              That is a nice step by step guide.
                              Thank you for updating post.

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