Results 1 to 3 of 3

Thread: Block close dialog

  1. #1
    Join Date
    Feb 2007
    Posts
    39
    Thanks
    13
    Qt products
    Qt4
    Platforms
    Windows

    Default Block close dialog

    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

    Qt Code:
    1. void MyMainDialog::done( int res )
    2. {
    3.  
    4. if( allowClose )
    5. QDialog::done(res);
    6. }
    7.  
    8.  
    9.  
    10. void MyMainDialog::closeEvent( QCloseEvent* e )
    11. {
    12.  
    13. if( allowClose )
    14. e->accept();
    15. else
    16. e->ignore();
    17. }
    To copy to clipboard, switch view to plain text mode 

    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

    Qt Code:
    1. void MyMainDialog::text_dialog()
    2. {
    3.  
    4. text_dlg = new QDialog( this );
    5. dlg_layout = new QVBoxLayout( text_dlg );
    6. ..........
    7. ..........
    8. text_dlg->exec();
    9. }
    To copy to clipboard, switch view to plain text mode 

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Block close dialog

    Hi,

    if your code in MyMainDialog works well, just subclass QDialog aka MyNoCloseableDialog with the two modifications and use it.
    Qt Code:
    1. text_dlg = new MyNoCloseableDialog( this );
    To copy to clipboard, switch view to plain text mode 

    Lykurg

  3. The following user says thank you to Lykurg for this useful post:

    Mrdata (12th March 2007)

  4. #3
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Block close dialog

    Or install an event filter on all dialogs you wish blocked and reject the close event:

    Qt Code:
    1. bool MyClass::eventFilter(QObject *o, QEvent *e){
    2. if(e->type()==QEvent::Close){
    3. e->ignore();
    4. return true;
    5. }
    6. return BaseClass::eventFilter(o, e);
    7. }
    8.  
    9. //...
    10. wishToBeBlocked->installEventFilter(MyClassInstance);
    To copy to clipboard, switch view to plain text mode 

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

  5. The following user says thank you to wysota for this useful post:

    Mrdata (12th March 2007)

Similar Threads

  1. Replies: 2
    Last Post: 5th February 2007, 17:42
  2. Replies: 1
    Last Post: 1st February 2007, 17:07
  3. Replies: 3
    Last Post: 16th November 2006, 12:24
  4. Replies: 3
    Last Post: 23rd July 2006, 18:02
  5. Show/hide part of dialog with resizing.
    By Spockmeat in forum Qt Tools
    Replies: 6
    Last Post: 7th June 2006, 08:22

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.