Results 1 to 7 of 7

Thread: Need don't show this message again check box in QMessageBox with YesNo button

  1. #1
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Need don't show this message again check box in QMessageBox with YesNo button

    Dear All,
    I want to have "Don't show this message again" check box in QMessageBox with Yes & No buttons , is there a way in Qt to achieve it ?
    I know there is QErrorMessage which gives this check box but I also need yes no button.

    Please help.

    Thank you,
    With Best Regards,
    Last edited by Rajesh.Rathod; 25th June 2014 at 06:17. Reason: updated contents

  2. #2
    Join Date
    Jul 2008
    Location
    Germany
    Posts
    507
    Thanks
    11
    Thanked 76 Times in 74 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Need don't show this message again check box in QMessageBox with YesNo button

    Hi, ugly hack:
    you can derive a class from QMessageBox, and if you look at the Qt sources you can see that QMessageBox uses a QGridLayout internally (at least in Qt4). You can get this using layout (), and then add a widget like a checkbox to it.

    This depends on Qt internals, so maybe/probably there is a better way to do it.

    Ginsengelf

    edit: of course you could just create a custom dialog for this...

  3. #3
    Join Date
    Sep 2009
    Location
    Wroclaw, Poland
    Posts
    1,394
    Thanked 342 Times in 324 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Need don't show this message again check box in QMessageBox with YesNo button

    Since Qt 5.2, QMessageBox supports setting custom check box with QMessageBox::setCheckBox method. If you are using older version, you will have to create a custom widget yourself.

  4. #4
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need don't show this message again check box in QMessageBox with YesNo button

    Dear All,
    Thank you very much for you help, I am using Qt 4.7.3 so can't use the latest API.

    Actaully, I found a workaround here...

    Qt Code:
    1. QMessageBox msgBox;
    2. QCheckBox dontShowCheckBox("don't show this message again");
    3. msgBox.addButton(&dontShowCheckBox, QMessageBox::ActionRole);
    To copy to clipboard, switch view to plain text mode 

    This seems to work for me, of course I need to connect signal slot and then I need to maintain it's checked state somewhere in my application....

    Thank you.

  5. #5
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need don't show this message again check box in QMessageBox with YesNo button

    Dear All,
    I have managed to show "Don't show message again" check box on QMessageBox in Qt 4.7.3 but now problem is the moment I clicks on check box it terminates message box and I don't want it.
    I wanted to mark the check box only, please help if anyone has any idea.
    Here is the sample code.

    Qt Code:
    1. QMessageBox msgBox;
    2. msgBox.setText(WMC_ASSIGNMENT_OVERWRITE_MSG);
    3. msgBox.setIcon(QMessageBox::Warning);
    4. QCheckBox dontShowCheckBox("don't show this message again");
    5. dontShowCheckBox.setCheckable(true);
    6. msgBox.addButton(&dontShowCheckBox, QMessageBox::ApplyRole);
    7. msgBox.addButton(QMessageBox::Ok);
    8. msgBox.addButton(QMessageBox::Cancel);
    9. msgBox.setDefaultButton(QMessageBox::Cancel);
    10. int32_t userReply = msgBox.exec();
    To copy to clipboard, switch view to plain text mode 


    Added after 1 8 minutes:


    Dear All,
    Finally, I managed to get what I wanted and here is the sample code of QMessageBox with "Don't show this message box again" check box in Qt 4.7.3.

    Qt Code:
    1. QMessageBox msgBox;
    2. msgBox.setText("Sample message text");
    3. msgBox.setIcon(QMessageBox::Warning);
    4. msgBox.addButton(QMessageBox::Ok);
    5. msgBox.addButton(QMessageBox::Cancel);
    6. msgBox.setDefaultButton(QMessageBox::Cancel);
    7. QCheckBox dontShowCheckBox("don't show this message again");
    8. dontShowCheckBox.blockSignals(true);
    9. msgBox.addButton(&dontShowCheckBox, QMessageBox::ResetRole);
    10. int32_t userReply = msgBox.exec();
    11. if(userReply == QMessageBox::Ok)
    12. {
    13. if(dontShowCheckBox.checkState() == Qt::Checked)
    14. {
    15. //Write function to handle this use case.
    16. }
    17. }
    To copy to clipboard, switch view to plain text mode 

    Thank you.
    Last edited by Rajesh.Rathod; 26th June 2014 at 09:39. Reason: updated contents

  6. #6
    Join Date
    May 2014
    Posts
    2
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Need don't show this message again check box in QMessageBox with YesNo button

    Why not just create your own dialog and display it as a message box (instead of using QMessageBox)?

  7. #7
    Join Date
    Apr 2012
    Location
    India.
    Posts
    88
    Thanked 8 Times in 8 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Need don't show this message again check box in QMessageBox with YesNo button

    @Wadashe : According to me this is small and reliable solution compare to writing complete class for displaying message box, isn't it?

Similar Threads

  1. How to add a a Button to a QMessageBox?
    By Bong.Da.City in forum Newbie
    Replies: 5
    Last Post: 29th August 2010, 20:02
  2. Check if there is message handler
    By Althor in forum Newbie
    Replies: 3
    Last Post: 14th July 2010, 15:02
  3. Replies: 4
    Last Post: 12th October 2008, 13:47
  4. StatusBar show message
    By Pang in forum Qt Programming
    Replies: 3
    Last Post: 23rd August 2007, 10:22
  5. get button on QMessageBox
    By manhds in forum Qt Programming
    Replies: 3
    Last Post: 27th June 2006, 04:38

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.