Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2647083
  • 博文数量: 416
  • 博客积分: 10220
  • 博客等级: 上将
  • 技术积分: 4193
  • 用 户 组: 普通用户
  • 注册时间: 2006-12-15 09:47
文章分类

全部博文(416)

文章存档

2022年(1)

2021年(1)

2020年(1)

2019年(5)

2018年(7)

2017年(6)

2016年(7)

2015年(11)

2014年(1)

2012年(5)

2011年(7)

2010年(35)

2009年(64)

2008年(48)

2007年(177)

2006年(40)

我的朋友

分类: C/C++

2009-06-02 09:16:58

#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();
}
阅读(2463) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~