900字范文,内容丰富有趣,生活中的好帮手!
900字范文 > qt 取消按钮点击效果_Qt 对话框里添加确定取消按钮

qt 取消按钮点击效果_Qt 对话框里添加确定取消按钮

时间:2019-11-12 05:57:48

相关推荐

qt 取消按钮点击效果_Qt 对话框里添加确定取消按钮

有时候需要弹出一个小对话框,不想用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按钮会有响应。

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。