Results 1 to 5 of 5

Thread: QMessageBox & QCheckBox problem

  1. #1
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QMessageBox & QCheckBox problem

    Hi everyone

    I need to place a check box in a message box and I try to do it like this
    Qt Code:
    1. QMessageBox msgBox(QMessageBox::Warning, "", "Do You wish to save file?",
    2. 0, this, Qt::Sheet);
    3. QCheckBox dontPrompt("Do not prompt again", &msgBox);
    4. msgBox.addButton(&dontPrompt, QMessageBox::ActionRole);
    5. QPushButton* pOK = msgBox.addButton("OK", QMessageBox::AcceptRole);
    6. pOK->setMaximumSize(200, 31);
    7. pOK->setMinimumSize(70, 31);
    8. msgBox.exec();
    To copy to clipboard, switch view to plain text mode 
    But when I click a check Box the message box closes
    Its very strange because I set Button role to QMessageBox::ActionRole which is
    QMessageBox::ActionRole - Clicking the button causes changes to the elements within the dialog, without closing the dialog.
    C++ & AMD forever

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: QMessageBox & QCheckBox problem

    J-P Nurmi

  3. #3
    Join Date
    Mar 2007
    Location
    Ukraine, Odessa
    Posts
    140
    Thanks
    15
    Thanked 11 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QMessageBox & QCheckBox problem

    Its not possible to do this with vanilla Qt?
    C++ & AMD forever

  4. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QMessageBox & QCheckBox problem

    you can add checkBox via
    Qt Code:
    1. msgBox.layout()->addWidget()
    To copy to clipboard, switch view to plain text mode 
    , but it's not good idea.

  5. #5
    Join Date
    Jun 2010
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Wink Re: QMessageBox & QCheckBox problem

    Here a solution I found

    Qt Code:
    1. QMessageBox msgBox(icon, title, text, 0, parent);
    2. QCheckBox dontPrompt(QObject::tr("Do not prompt again"), &msgBox);
    3.  
    4. // HACK: BLOCKING SIGNALS SO QMessageBox WON'T CLOSE
    5. dontPrompt.blockSignals(true);
    6.  
    7. msgBox.addButton(&dontPrompt, QMessageBox::ActionRole);
    8.  
    9. QAbstractButton* pYES = (QAbstractButton*)msgBox.addButton(QMessageBox::Yes);
    10. QAbstractButton* pNO = (QAbstractButton*)msgBox.addButton(QMessageBox::No);
    11. msgBox.exec();
    12.  
    13. if ( dontPrompt.checkState() == Qt::Checked )
    14. {
    15. // TODO: YOUR CODE HERE
    16. }
    To copy to clipboard, switch view to plain text mode 

    It works for me
    Daniele
    I Qt 4.6

Similar Threads

  1. Steps in solving a programming problem?
    By triperzonak in forum General Programming
    Replies: 8
    Last Post: 5th August 2008, 08:47
  2. QMessageBox problem in Qtopia
    By jogeshwarakundi in forum Qt for Embedded and Mobile
    Replies: 5
    Last Post: 8th February 2008, 09:22
  3. Replies: 16
    Last Post: 7th March 2006, 15:57

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.