Qt 对话框里添加确定取消按钮
2014-08-12 16:15
671 查看
有时候需要弹出一个小对话框,不想用designer设计,直接在代码里动态的生成。
如下图所示:弹出一个带下拉列表和确定取消按钮的对话框
点击OK和NO按钮会有响应。
如下图所示:弹出一个带下拉列表和确定取消按钮的对话框
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按钮会有响应。
相关文章推荐
- QT的一个奇怪问题,设置了Qt::Tool后,点击弹出对话框的确定取消按钮,程序直接退出
- QT的一个奇怪问题,设置了Qt::Tool后,点击弹出对话框的确定取消按钮,程序直接退出。
- QT的一个奇怪问题,设置了Qt::Tool后,点击弹出对话框的确定取消按钮,程序直接退出
- 为什么用mfc创建的对话框中确定和取消按钮上的字是横着的
- android Dialog的确定按钮点击后不取消对话框
- Window对象的常用方法中带有提示信息、确定和取消按钮的对话框
- 安卓单选对话框之带确定和取消按钮
- IOS之UIPickerView添加确定,取消按钮
- Android: 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框,禁止按[返回键]或[搜索键]关闭
- 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框
- 服务器端按钮弹出确定取消对话框的例子
- 新手求教android的checkBox问题,现在我想实现按一个按钮,弹出一个对话框,这个对话框有标题,两列多行的checkBox以及最后的确定取消按钮,咋做?
- Android: 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框,禁止按[返回键]或[搜索键]关闭
- 如何删除CPropertySheet 类派生生成的标签对话框上的默认按钮 “确定”“取消”“删除”
- Qt学习(二) 创建对话框,添加按钮
- 服务器端按钮添加客户端事件(确定、取消执行)
- MFC取消HtmlDialog对话框的"确定"和"取消"按钮方法
- Android: 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框,禁止按[返回键]或[搜索键]关闭
- PickerView添加确定,取消按钮
- Android: 创建一个AlertDialog对话框,必须按确定或取消按钮才能关闭对话框,禁止按[返回键]或[搜索键]关闭