您的位置:首页 > 编程语言 > Qt开发

Qt 对话框里添加确定取消按钮

2014-08-12 16:15 671 查看
有时候需要弹出一个小对话框,不想用designer设计,直接在代码里动态的生成。

如下图所示:弹出一个带下拉列表和确定取消按钮的对话框

QDialog  dialog;
dialog.setWindowTitle(tr("选择要保存的格式"));

QComboBox *box = new QComboBox(&dialog);
box->addItem("jpg");
box->addItem("bmp");
box->addItem("png");
box->addItem("tif");
box->addItem("img");

QDialogButtonBox *button = new QDialogButtonBox(&dialog);
button->addButton( "OK", QDialogButtonBox::YesRole);
button->addButton( "NO", QDialogButtonBox::NoRole);
connect(button, SIGNAL(accepted()), &dialog, SLOT(accept()));
connect(button, SIGNAL(rejected()), &dialog, SLOT(reject()));

QVBoxLayout *layout = new QVBoxLayout;
layout->addWidget(box);
layout->addWidget( button);
dialog.setLayout(layout);

QString suffix ;
if ( dialog.exec() == QDialog::Accepted)
{

suffix = box->currentText();
ImageConvert img;
img.ConvertImages( files, dstpath.toStdString(), suffix.toStdString());
}




点击OK和NO按钮会有响应。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐