[SOLVED] Recommended Approach for Inline Modal
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.
Im not 100% sure the exact effect you want
so I will just suggest some stuff. bare with me :)
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.
@mrjj I tried to follow your instructions in Qt5.5 Creator but they didn't line up.
what did not line up?
Did you inline it or use frameless dialogs?
New > QT Designer > Dialog. Doesn't exist. Did you mean Designer Form or Designer Form Class?
Add stuff to the new dialog.
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"?
Rightclick the centralWidget and choose Promote. I did this in the main window. I see a dialog that looks like this:
I have no clue what to put in those fields.
Sorry . didn't write all steps.
Yes its Designer Form Class, then choose Dialog in center.
The edit controls or what you want to be displayed in the mainform in your inline dialog. buttons and such.
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.
Promoted class name,
we must type the name of the dialog class.
or whatever you call it in (1).
Note big/small letters.
you must type name of header file.
(this is most likely small letters)
Then Press Add button
and now you can press the Promote button.
Hope this is better to follow.
@mrjj Okay, I added it (called it "Dialog") and this is what that form looks like:
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?
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 ?)
Ok it looks like you did it right.
So how do you mainscreen look like before you run it ?
Ok. sorry. I remembered wrong.
Select Type "Widget" in step 1.
Default name will be Form
in promote dialog,
and "add" and "promote"
Just made small test here to be sure.
@mrjj Worked! Awesome!
Super :) sorry for the confusion.
I hope its what you wanted.
@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.
@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:
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.
That is a nice step by step guide.
Thank you for updating post.