QFileDialog dialog(this);
dialog.setFileMode(QFileDialog::ExistingFiles);
dialog.setNameFilter(tr("All Files (*);;Text Files (*.txt)"));
dialog.setViewMode(QFileDialog::List);
// dialog.setOption(QFileDialog::DontUseNativeDialog,true);
dialog.setLabelText(QFileDialog::Accept, "确定ok");
dialog.setLabelText(QFileDialog::Reject, "取消cancel");
dialog.setLabelText(QFileDialog::FileName, "FileName dd");
dialog.setLabelText(QFileDialog::FileType, "FileType dd");
dialog.setLabelText(QFileDialog::LookIn, "LookIn dd");
dialog.selectFile("D:/Hui_Program/UpperComputerDetectionPlatform/debug/UpperComputerDetectionPlatform.exe");
dialog.setDirectory("D:/Hui_Program/UpperComputerDetectionPlatform/debug/Config");
connect(&dialog, &QFileDialog::fileSelected,this, [=](const QString &file) {
OutputDebug << "fileSelected " << file;
});
connect(&dialog, &QFileDialog::filesSelected,this, [=](const QStringList &files) {
OutputDebug << "filesSelected " << files;
});
connect(&dialog, &QFileDialog::currentChanged,this, [=](const QString &path) {
OutputDebug << "currentChanged path " << path;
});
connect(&dialog, &QFileDialog::directoryEntered,this, [=](const QString &directory) {
OutputDebug << "directoryEntered directory" << directory;
});
connect(&dialog, &QFileDialog::filterSelected,this, [=](const QString &filter) {
OutputDebug << "filterSelected filter" << filter;
});
connect(&dialog, &QFileDialog::currentUrlChanged,this, [=](const QUrl &url) {
OutputDebug << "currentUrlChanged url" << url;
});
QStringList fileNames;
QString strCurSelectDir = "";
int iRtn = dialog.exec();
if (iRtn)
strCurSelectDir = dialog.directory().absolutePath();
QDir dir(strCurSelectDir);
QFileInfoList listFileInfo = dir.entryInfoList(QDir::NoDotAndDotDot | QDir::Files);
QFileInfo fileInfo;
for (int iIndex = 0; iIndex < listFileInfo.size(); ++iIndex) {
fileInfo = listFileInfo.at(iIndex);
OutputDebug << "fileInfo.absoluteFilePath()" << fileInfo.absoluteFilePath();
OutputDebug << "fileInfo.absolutePath()" << fileInfo.absolutePath();
OutputDebug << "fileInfo.baseName()" << fileInfo.baseName();
OutputDebug << "fileInfo.fileName()" << fileInfo.fileName();
OutputDebug << "fileInfo.filePath()" << fileInfo.filePath();
OutputDebug << "fileInfo.bundleName()" << fileInfo.bundleName();
OutputDebug << "fileInfo.completeSuffix()" << fileInfo.completeSuffix();
OutputDebug << "fileInfo.completeBaseName()" << fileInfo.completeBaseName();
}
QFileDialog 自定义文件对话框
最新推荐文章于 2024-08-27 14:10:57 发布