Page 2 of 2 FirstFirst 12
Results 21 to 30 of 30

Thread: Disable Close button (X) of a QDialog

  1. #21
    Join Date
    Jan 2006
    Location
    Ljubljana
    Posts
    687
    Thanks
    111
    Thanked 4 Times in 4 Posts
    Qt products
    Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Disable Close button (X) of a QDialog

    Quote Originally Posted by BrainB0ne View Post
    That's very nice to hear/know when i'm going to use Qt 4.5 or higher in the future!
    Very nice, thanks, but, is it possible to disable (X) in dialog that resided on QGraphicsView, I've read in the docs that is NOT possible ...
    Qt 5.3 Opensource & Creator 3.1.2

  2. #22
    Join Date
    Apr 2009
    Location
    China
    Posts
    127
    Thanks
    30
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Disable Close button (X) of a QDialog

    I use the same code in QT4.5, but it doesn't work!!
    why??

  3. #23
    Join Date
    May 2009
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Disable Close button (X) of a QDialog

    Quote Originally Posted by blue.death View Post
    Anybody knows how to disable that nasty little button on X11 and Mac OS X??
    I have the exact same problem. I'm using Qt 4.3 and don't have the luxury of Qt::WindowMinMaxButtonHint.

    I need to keep the title bar empty, so Qt::FramelessWindowHint makes the message box a bit bare.

    It was suggested that we can inherit a QDialog box and disable it there...would anyone else know of any other suggestions?

    Thanks,
    Kat

  4. #24
    Join Date
    Jan 2006
    Location
    Russia
    Posts
    16
    Thanked 5 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    Quote Originally Posted by kyue View Post
    It was suggested that we can inherit a QDialog box and disable it there...would anyone else know of any other suggestions?
    try upgrading to qt 4.5

  5. #25
    Join Date
    Dec 2006
    Posts
    426
    Thanks
    8
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Disable Close button (X) of a QDialog

    Try this

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qevent.h>
    3. #include <qpushbutton.h>
    4. #include <qdialog.h>
    5. #include <qmessagebox.h>
    6. #include <iostream>
    7.  
    8. class MyDialog : public QDialog
    9. {
    10. public:
    11.  
    12. MyDialog( QWidget* parent=0 ) : QDialog( parent ) {
    13. }
    14.  
    15. protected:
    16.  
    17. void closeEvent ( QCloseEvent * event ) {
    18. event->ignore();
    19. QMessageBox::information( this, "Close?", "Close? No way!" );
    20. }
    21. };
    22.  
    23. int main( int argc, char** argv )
    24. {
    25. QApplication app( argc, argv );
    26.  
    27. MyDialog dlg;
    28. QPushButton* button = new QPushButton( "Exit", &dlg );
    29. QObject::connect( button, SIGNAL( clicked() ),
    30. &app, SLOT( quit() ) );
    31. dlg.resize( 300, 300 );
    32. dlg.show();
    33.  
    34. return app.exec();
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 

  6. #26
    Join Date
    May 2009
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Disable Close button (X) of a QDialog

    Quote Originally Posted by shad View Post
    try upgrading to qt 4.5
    Sorry, I didn't see these replies until now. It's not an option for us right now.

  7. #27
    Join Date
    May 2009
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Disable Close button (X) of a QDialog

    Quote Originally Posted by lni View Post
    Try this

    Qt Code:
    1. #include <qapplication.h>
    2. #include <qevent.h>
    3. #include <qpushbutton.h>
    4. #include <qdialog.h>
    5. #include <qmessagebox.h>
    6. #include <iostream>
    7.  
    8. class MyDialog : public QDialog
    9. {
    10. public:
    11.  
    12. MyDialog( QWidget* parent=0 ) : QDialog( parent ) {
    13. }
    14.  
    15. protected:
    16.  
    17. void closeEvent ( QCloseEvent * event ) {
    18. event->ignore();
    19. QMessageBox::information( this, "Close?", "Close? No way!" );
    20. }
    21. };
    22.  
    23. int main( int argc, char** argv )
    24. {
    25. QApplication app( argc, argv );
    26.  
    27. MyDialog dlg;
    28. QPushButton* button = new QPushButton( "Exit", &dlg );
    29. QObject::connect( button, SIGNAL( clicked() ),
    30. &app, SLOT( quit() ) );
    31. dlg.resize( 300, 300 );
    32. dlg.show();
    33.  
    34. return app.exec();
    35.  
    36. }
    To copy to clipboard, switch view to plain text mode 
    Thank you for your reply. Yes, this was a solution that was considered. I'm wondering if there is another solution where we don't have to inherit and ignore the closeEvent...

  8. #28
    Join Date
    May 2009
    Posts
    18
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Disable Close button (X) of a QDialog

    If this helps anyone, you can remove the three buttons on the top left (close, minimize, maximize) on a Mac and leaving the title there using:

    Qt Code:
    1. setWindowModality(Qt::WindowModal);
    To copy to clipboard, switch view to plain text mode 

  9. #29
    Join Date
    May 2006
    Location
    Bangalore,India
    Posts
    235
    Thanks
    7
    Thanked 25 Times in 24 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Windows

    Default Re: Disable Close button (X) of a QDialog

    try Window flags
    see the example: http://doc.trolltech.com/4.3/widgets-windowflags.html

  10. #30
    Join Date
    Dec 2009
    Posts
    128
    Thanks
    7
    Thanked 14 Times in 14 Posts
    Platforms
    Unix/X11 Windows

    Arrow Re: Disable Close button (X) of a QDialog

    hi

    this did the job for me (on a QDialog based class) :

    Qt Code:
    1. Qt::WindowFlags flags = windowFlags() ;
    2. flags |= Qt::CustomizeWindowHint ;
    3. flags &= ~Qt::WindowCloseButtonHint ;
    4. setWindowFlags( flags ) ;
    To copy to clipboard, switch view to plain text mode 

  11. The following user says thank you to totem for this useful post:

    ttimt (22nd February 2014)

Similar Threads

  1. Diasble close button on a QDialog
    By Krish_ng in forum Qt Programming
    Replies: 12
    Last Post: 17th July 2007, 05:23
  2. Replies: 1
    Last Post: 7th July 2007, 10:03
  3. Disable Checkable Button Question
    By jbpvr in forum Qt Programming
    Replies: 9
    Last Post: 20th March 2007, 18:57
  4. Replies: 2
    Last Post: 5th February 2007, 18:42
  5. Replies: 3
    Last Post: 16th November 2006, 13:24

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.