PDA

View Full Version : QMessageBox & QCheckBox problem



THRESHE
4th August 2008, 14:09
Hi everyone

I need to place a check box in a message box and I try to do it like this


QMessageBox msgBox(QMessageBox::Warning, "", "Do You wish to save file?",
0, this, Qt::Sheet);
QCheckBox dontPrompt("Do not prompt again", &msgBox);
msgBox.addButton(&dontPrompt, QMessageBox::ActionRole);
QPushButton* pOK = msgBox.addButton("OK", QMessageBox::AcceptRole);
pOK->setMaximumSize(200, 31);
pOK->setMinimumSize(70, 31);
msgBox.exec();

But when I click a check Box the message box closes :confused:
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.

jpn
4th August 2008, 14:25
See QxtConfirmationMessage (http://doc.libqxt.org/latest/classQxtConfirmationMessage.html) ;)

THRESHE
4th August 2008, 16:34
Its not possible to do this with vanilla Qt? :confused:

spirit
4th August 2008, 16:51
you can add checkBox via
msgBox.layout()->addWidget() , but it's not good idea.:)

OpenNingia
10th June 2010, 10:23
Here a solution I found



QMessageBox msgBox(icon, title, text, 0, parent);
QCheckBox dontPrompt(QObject::tr("Do not prompt again"), &msgBox);

// HACK: BLOCKING SIGNALS SO QMessageBox WON'T CLOSE
dontPrompt.blockSignals(true);

msgBox.addButton(&dontPrompt, QMessageBox::ActionRole);

QAbstractButton* pYES = (QAbstractButton*)msgBox.addButton(QMessageBox::Ye s);
QAbstractButton* pNO = (QAbstractButton*)msgBox.addButton(QMessageBox::No );
msgBox.exec();

if ( dontPrompt.checkState() == Qt::Checked )
{
// TODO: YOUR CODE HERE
}


It works for me :)