[SOLVE] How to set order show of Dialog?
-
Hi all,
I have 2 dialog such as: Dialog.cpp and Dialog2.cpp class
in constructure's Dialog a call show Dialog2 as :
@Dialog::Dialog(QWidget *parent) :
QDialog(parent),_dialog2(NULL),
ui(new Ui::Dialog)
{
ui->setupUi(this);
if(_dialog2 == NULL){
_dialog2 = new Dialog2();
}
_dialog2->show();
}
@
Result is Dialog2 show precede and Dialog follow auto. But now I want reverse, Dialog will showed preceding and then Dialog2 showed.
Brief, How to set order show of Dialog automatic? How to check a dialog actually showed in monitor?
I try to:
@ if(dialog1->isVisible()){
dialog1->hide();
dialog2->show();
}
@
But I don't see the dialog1 appearance. Only dialog2 showed. -
The problem is that you are using _dialog2->show() inside the constructor of Dialog and I guess the instance to Dialog->show() is called later. AFAIK there is no automatic way to set the order in which the dialog will show, It completely depends when you want call show() function for a widget.
So may be you can create an instance of dialog2 in the constructor and call _dialog2->show() when Dialog is already visible.
You can override eventFilter() for Dialog class and then check for QEvent::Show or check QWidget::showEvent() and accordingly call _dialog2->show().
-
Main problem I see is that you couple 'order' logic with objects which are part of this logic: you create one dialog inside almost created another dialog, as pointed Sam. In my opinion you should create some kind of DialogOrderCreator which can create your dialogs in proper way, without any direct dependencies between your dialogs.
-
Hi all,
Thank you for your help,
I try to use:
@void Dialog::showEvent(QShowEvent *showEvent){
if(showEvent->type() == QEvent::Show){
this->_dialog2->show();
}
}@
but dialog1 also show preceding dialog2.
Thanks. -
Yes, showEvent() get called just before your Dialog display, so you still make dialog2 shown before dialog1
[quote author="phamvanan" date="1374027544"]Hi all,
Thank you for your help,
I try to use:
@void Dialog::showEvent(QShowEvent *showEvent){
if(showEvent->type() == QEvent::Show){
this->_dialog2->show();
}
}@
but dialog1 also show preceding dialog2.
Thanks. [/quote] -
[quote author="phamvanan" date="1373971710"]Hi all,
I have 2 dialog such as: Dialog.cpp and Dialog2.cpp class
in constructure's Dialog a call show Dialog2 as :
Dialog::Dialog(QWidget *parent) :
QDialog(parent),_dialog2(NULL),
ui(new Ui::Dialog)
{
ui->setupUi(this);
if(_dialog2 == NULL){
_dialog2 = new Dialog2();
}
_dialog2->show();
}
[/quote]Just replace
@
_dialog2->show();
@with
@
QTimer::singleShot(0, _dialog2, SLOT(show()));
@should work.
-
Thank you very much.z