QDialog
- Dialog 和 Widget 的区别 Dialog 无放大缩小按钮
模态对话框
dlg->exec();
模态对话框 在模态对话框中 exec 有自己的消息循环并把 app 的消息循环接管了
dialog 是通过 exec 来显示 可通过 accept 和 reject 来关闭窗口
dlg->show();
- 普通对话框用 close( ) 关闭
QFileDialog
- 用于打开文件 保存文件等
QFileDialog * f_dlg;
f_dlg = new QFileDialog(NULL,"filedlg",_strDir,"Png File (*.png)");
- getSaveFileName
// 返回的文件目录储存在 strFilename 用于下一次打开时在当前目录
QString strFilename =
QFileDialog::getSaveFileName(NULL,
"filedlg", // Title
_strDir, // Dir
"Png File (*.png)" // file type
);
// 创建一个 QFileInfo 存储上一步的文件路径
QFileInfo fileinfo(strFilename);
_strDir = fileinfo.filePath();
QMessageBox
QMessageBox::warning(this, "Error", "Error msgs ....");
QMessageBox::information(this, "Error", "information msgs ....");
// x 符号那种
QMessageBox::critical(this,"critical", "critical msgs .....");
// 选择
int ret = QMessageBox::question(this, "???", "ready do ?",
QMessageBox::Yes| QMessageBox::No | QMessageBox::Ok | QMessageBox::NoAll);
if(ret == QMessageBox::Yes)
{
qDebug() << "yes";
}
if(ret == QMessageBox::No)
{
qDebug() << "no";
}
其他的 Dialog
- QColorDialog
- QFontDialog