PDA

View Full Version : Block close dialog



Mrdata
12th March 2007, 13:50
I've the following problem, i want to block the user to close dialog using the 'X' icon or escape key, i know that using something like this will work



void MyMainDialog::done( int res )
{

if( allowClose )
QDialog::done(res);
}



void MyMainDialog::closeEvent( QCloseEvent* e )
{

if( allowClose )
e->accept();
else
e->ignore();
}


Above code works fine and blocks the main dialog,
but now i created this dialog called from maindialog and i want also to block it



void MyMainDialog::text_dialog()
{

text_dlg = new QDialog( this );
dlg_layout = new QVBoxLayout( text_dlg );
..........
..........
text_dlg->exec();
}


Something like connect( on_close_text_dlg, SIGNAL(clicked()), this, SLOT( block_it() ));
will be the proper way to do this? i tried, but couldn't find what will be the way to receive the event type for a on_close_text_dlg
How i block the text_dlg?

Lykurg
12th March 2007, 15:03
Hi,

if your code in MyMainDialog works well, just subclass QDialog aka MyNoCloseableDialog with the two modifications and use it.
text_dlg = new MyNoCloseableDialog( this );

Lykurg

wysota
12th March 2007, 16:39
Or install an event filter on all dialogs you wish blocked and reject the close event:


bool MyClass::eventFilter(QObject *o, QEvent *e){
if(e->type()==QEvent::Close){
e->ignore();
return true;
}
return BaseClass::eventFilter(o, e);
}

//...
wishToBeBlocked->installEventFilter(MyClassInstance);

This way you can switch on and off the block by installing or removing the filter.