Embed QDialog as QWidget
-
Hello,
I found a new feature of Qt what could help much for my projects.Background:
The current version of my software consist of a lot of MID- and modal dialogs for the work flow. Now, my customer wants a more compact design, where all work will be executed in more or less in ONE window.
Reprogram all funktion in this ONE window or in QFrames is a lot of work.Solution:
A very elegant methode is, to ingegrate my derived QDialog in a Layout as a widget. This works like a charme, without much effort ! Nevertheless I read in the internet this is strict not recommend !
Has somebody experiences with this methode ? Has it big disadvantages or produces problems later ? -
Hi,
Depending on the logic you put in your dialogs, a search and replace to change the base class from QDialog to QWidget should be enough.
That said, the usual issue with the cases reported online were from people trying to use QDialog as a base class for no good reason or trying to abuse its API.
-
@SGaist said in Embed QDialog as QWidget:
Hi,
Depending on the logic you put in your dialogs, a search and replace to change the base class from QDialog to QWidget should be enough.
That said, the usual issue with the cases reported online were from people trying to use QDialog as a base class for no good reason or trying to abuse its API.
Hi,
I dont understand what you mean, with the replacing.
My stratgie is much more simpler, because I use the QDialog directy.class MyDialog: public QDialog {.... } // in an other dialog: MyDialog* f=new MyDialog(this); ui->A_QFrame->layout()->addWidget(f);
So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want.
-
@Andy314 said in Embed QDialog as QWidget:
I dont understand what you mean, with the replacing
Search and replace ": public QDialog" to ": public QWidget".
"So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want" - the correct approach for this would be to create a QWidget based class which you can use directly or put in a QDialog.
-
@jsulm said in Embed QDialog as QWidget:
@Andy314 said in Embed QDialog as QWidget:
I dont understand what you mean, with the replacing
Search and replace ": public QDialog" to ": public QWidget".
"So I can use my dialog twice as a standard allone window and as a integration in an other dialog if i want" - the correct approach for this would be to create a QWidget based class which you can use directly or put in a QDialog.
Ok, I undsterstand. Transform the QDialog to a QWidget and use it as base with promoting in other dialogs is the cleanest solution. Nevertheless it works without this transformation too. The questions is, if later Qt-Version will break this technik.
For my project its a little more compilcated, because my dialogs have not the QDialog as direct parent. I have my specialized dialog in chain of inherience with a lot of fundamental functions/communication/model-view interface .
So the direct integration of the dialog will be easier, but mybe I will integrate it in a derived QWidget too. -
@Andy314 said in Embed QDialog as QWidget:
For my project its a little more compilcated, because my dialogs have not the QDialog as direct parent
They don't have to. You can put any QWidget into a QDialog. QDialog is a QWidget, so you can add layouts and widgets to it.
-