QDialog Inheritance
-
Hi!
I have 10 dialog windows, where at least 5 of them use the same scheme, i mean, same buttons, fixed window sizes and tables, just some names changes... and i was wondering if i can inheritance with it...something like this:
SuperClass_QDialogType : QDialog
MainDialogWindowType : SuperClass_QDialogType
WBuyDialog : MainDialogWindowType
WSellDialog : MainDialogWindowType
WAskDialog : MainDialogWindowType
..and so.MainDialogWindowType has all slots and signal for buttons and the table...
Does it has sense o better stay with no-inheritance with windows?
Thanks.
-
Hi,
Yes, it does make sense to write reusable widgets.
-
ok!... does the MainDialogWindowType needs to be a simple class or a Qt Designer form class in order to use slots and signals?
-
@U7Development
Hi
Any class that inherits from QObject/QWidget and has the Q_OBJECT
macro can use signals and slots. So you dont have to use Designer if not needed.However, QDialog has the option of being modal which QWidgets cannot. -
-
@Chris-Kawa
Oh that i completely missed! :) ( years later :)
So it can also spin local event loop and behave like QDialog ?
So the only real added feature of dialogs is what ever the platform adds for the windows flags and the accept / reject system ?
Or what does QDialog bring that QWidget cannot ? -
I'm not convince inheritance is the easier way for managing a few minor label/text changes AMHA.
One can define a Dialog type attribut instead:
enum DialogType { Buy, Sell, Ask }; DialogWindow(DialogType type, QWidget* parent=nullptr) : QDialog(parent) { switch(type) { case Buy: // make changes for Buy type break; ... } }
-
So a bit like QMessageBox or QInputDialog ?