#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
/*msgBox w;
w.show();*/
QMessageBox msgBox(QMessageBox::Warning, "", "Do You wish to save file?",
0, NULL, Qt::Sheet);
QCheckBox dontPrompt("Do not prompt again", &msgBox);
//msgBox.addButton(&dontPrompt, QMessageBox::ActionRole);
msgBox.layout()->addWidget(&dontPrompt);
QPushButton* pOK = msgBox.addButton("OK", QMessageBox::AcceptRole);
pOK->setMaximumSize(200, 31);
pOK->setMinimumSize(70, 31);
msgBox.exec();
bool b = dontPrompt.checkState();
qDebug() << "result=" << b;
return a.exec();
}
/**************************************/
// 改进版本 注意Title, 与addButton对象的位置
#include
#include
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
/*msgBox w;
w.show();*/
QMessageBox msgBox(QMessageBox::Warning, "Title Msg", "",
0, NULL, Qt::Sheet);
msgBox.setFixedWidth(200);
QCheckBox dontPrompt("Do not prompt again", &msgBox);
QCheckBox dontPrompt2("Do not prompt again8888888", &msgBox);
QPushButton* pAdd = new QPushButton("add");
QPushButton* pSave = msgBox.addButton(QMessageBox::Save);
QPushButton* pOK = msgBox.addButton(QMessageBox::Close);
QLabel* pLabel = new QLabel("ddddddddddddddddddddddddddddddddddddddddddddddddddddd\ndddddddddddddddddddddddddddddddddddd\nddddddddddddddddddddddddddddddddddddddddddddddddddddddd\ndddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddddd");
pLabel->setScaledContents(true);
pLabel->setIndent(20);
QSpacerItem *pSpacer = new QSpacerItem(40, 20, QSizePolicy::Expanding, QSizePolicy::Minimum);
dynamic_cast< QGridLayout *>(msgBox.layout())->addWidget(pLabel, 0, 1, 1, 4);
dynamic_cast< QGridLayout *>(msgBox.layout())->addWidget(&dontPrompt, 2, 1,1,4);
dynamic_cast< QGridLayout *>(msgBox.layout())->addWidget(&dontPrompt2, 3, 1,1,4);
dynamic_cast< QGridLayout *>(msgBox.layout())->addItem(pSpacer, 4, 1);
dynamic_cast< QGridLayout *>(msgBox.layout())->addWidget(pAdd, 4, 2);
dynamic_cast< QGridLayout *>(msgBox.layout())->addWidget(pSave, 4, 3);
dynamic_cast< QGridLayout *>(msgBox.layout())->addWidget(pOK, 4, 4);
int i=1;
QList lWgt = msgBox.buttons();
foreach(QAbstractButton *btn, lWgt)
{
qDebug() << "btn = " << btn->text();
i++;
}
//pOK->setMaximumSize(200, 31);
//pOK->setMinimumSize(70, 31);
msgBox.exec();
bool b = dontPrompt.checkState();
bool b2 = dontPrompt.checkState();
qDebug() << "result=" << b;
qDebug() << "result=" << b2;
return a.exec();
}
阅读(2503) | 评论(0) | 转发(0) |