Results 1 to 10 of 10

Thread: disable close button in QMessageBox

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jun 2011
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: disable close button in QMessageBox

    I found this thread because I had the same problem, but managed to solve it in a different way.
    Qt Code:
    1. mBox.setWindowTitle("Dialog Title");
    2. mBox.setText("Question?");
    3. mBox.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
    4.  
    5. Qt::WindowFlags wFlags = mBox.windowFlags();
    6. if(Qt::WindowCloseButtonHint == (wFlags & Qt::WindowCloseButtonHint))
    7. {
    8. wFlags = wFlags ^ Qt::WindowCloseButtonHint;
    9. mBox.setWindowFlags(wFlags);
    10. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by nmahoney; 3rd June 2011 at 15:46.

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

    Default Re: disable close button in QMessageBox

    The standard way is to allow the user to close the dialog using regular means and interpret this as if he pushed one of the buttons (usually the one related to "rejecting" the dialog -- most likely the "No" button in this example). The same goes with handling the Esc key.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2010
    Posts
    769
    Thanks
    1
    Thanked 94 Times in 86 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: disable close button in QMessageBox

    Quote Originally Posted by wysota View Post
    The standard way is to allow the user to close the dialog using regular means and interpret this as if he pushed one of the buttons (usually the one related to "rejecting" the dialog -- most likely the "No" button in this example). The same goes with handling the Esc key.
    Agree. Subverting normal UI conventions is very bad form. The user expects things to work as they always have, and will be frustrated if they don't.

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

    Default Re: disable close button in QMessageBox

    To explain further what I mean...

    Usually you want to disable the close button because you don't want the user to be able to close the window. Here the situation is different -- you want him to close the window (which will happen if he chooses a button from the dialog box) but only using the means chosen by you and not any other. There is no reason to do that.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 2
    Last Post: 26th April 2011, 11:44
  2. Disable Close button (X) of a QDialog
    By BrainB0ne in forum Qt Programming
    Replies: 29
    Last Post: 8th December 2009, 17:01
  3. Disable close button on QTabWidget/QTabBar
    By minimoog in forum Qt Programming
    Replies: 1
    Last Post: 16th March 2009, 05:25
  4. how to disable X button to close th window
    By raghvendramisra in forum Qt Programming
    Replies: 2
    Last Post: 5th February 2009, 20:01
  5. About QMessageBox close my tray application
    By Doles in forum Qt Programming
    Replies: 2
    Last Post: 19th July 2008, 21:27

Tags for this Thread

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
  •  
Qt is a trademark of The Qt Company.