本文整理汇总了C++中QFileDialog::selectNameFilter方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileDialog::selectNameFilter方法的具体用法?C++ QFileDialog::selectNameFilter怎么用?C++ QFileDialog::selectNameFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QFileDialog
的用法示例。
在下文中一共展示了QFileDialog::selectNameFilter方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: open
void AppImportFile::open()
{
const QString MetaIOImageFilter("MetaIO Image (*.mhd)"), DICOMImageFilter("DICOM Images (*.dcm)"), AllFilesFilter("All Files (*)");
QStringList imagesFilter;
imagesFilter << MetaIOImageFilter << DICOMImageFilter << AllFilesFilter;
QFileDialog *openDialog = new QFileDialog(0);
openDialog->setWindowTitle(tr("Select files to open..."));
openDialog->setDirectory(m_workingDirectory);
openDialog->setNameFilters(imagesFilter);
openDialog->selectNameFilter (m_lastExtension);
openDialog->setFileMode(QFileDialog::ExistingFiles);
openDialog->setAcceptMode(QFileDialog::AcceptOpen);
if (openDialog->exec() == QDialog::Accepted)
{
QStringList fileNames = openDialog->selectedFiles();
emit selectedFiles(fileNames);
m_workingDirectory = QFileInfo(fileNames.first()).dir().path();
m_lastExtension = openDialog->selectedNameFilter();
writeSettings();
}
delete openDialog;
}
示例2: on_actionAdd_File_triggered
void MainWindow::on_actionAdd_File_triggered()
{
this->settings->beginGroup(QStringLiteral("paths"));
QFileDialog *dialog = new QFileDialog(this);
DialogMaster::masterDialog(dialog);
dialog->setWindowTitle(tr("Open Icon Archive"));
dialog->setAcceptMode(QFileDialog::AcceptOpen);
dialog->setFileMode(QFileDialog::ExistingFiles);
dialog->setDirectory(this->settings->value(QStringLiteral("openPath")).toString());
QStringList mTypes = byteToStringList(QImageReader::supportedMimeTypes());
mTypes.append(QStringLiteral("application/octet-stream"));
dialog->setMimeTypeFilters(mTypes);
QString selFilter = this->settings->value(QStringLiteral("openFilter")).toString();
qDebug() << selFilter;
if(selFilter.isEmpty()) {
#if defined(Q_OS_WIN)
dialog->selectMimeTypeFilter(QStringLiteral("image/vnd.microsoft.icon"));
#elif defined(Q_OS_OSX)
dialog->selectMimeTypeFilter(QStringLiteral("image/x-icns"));
#else
dialog->selectMimeTypeFilter(QStringLiteral("image/png"));
#endif
} else
dialog->selectNameFilter(selFilter);
this->settings->endGroup();
dialog->open(this, SLOT(fileSelected(QStringList)));
}
示例3: getOpenFileName
/**
* Shows a dialog for choosing a file name. Opening the file is up to
* the caller.
*
* @return File name with path and extension to determine the file type
* or an empty string if the dialog was cancelled.
*/
QString QG_FileDialog::getOpenFileName(QWidget* parent, RS2::FormatType* type) {
RS_DEBUG->print("QG_FileDialog::getOpenFileName");
// read default settings:
RS_SETTINGS->beginGroup("/Paths");
QString defDir = RS_SETTINGS->readEntry("/Open",
RS_SYSTEM->getHomeDir());
//QString defFilter = RS_SETTINGS->readEntry("/OpenFilter",
// "Drawing Exchange (*.dxf *.DXF)");
QString defFilter = "Drawing Exchange (*.dxf)";
RS_SETTINGS->endGroup();
RS_DEBUG->print("defDir: %s", defDir.toLatin1().data());
RS_DEBUG->print("defFilter: %s", defFilter.toLatin1().data());
QString fDxfOld(QObject::tr("Old Drawing Exchange %1").arg("(*.dxf *.DXF)"));
QString fDxfrw(QObject::tr("Drawing Exchange %1").arg("(*.dxf)"));
QString fDxf1(QObject::tr("QCad 1.x file %1").arg("(*.dxf *.DXF)"));
QString fLff(QObject::tr("LFF Font %1").arg("(*.lff)"));
QString fCxf(QObject::tr("Font %1").arg("(*.cxf)"));
QString fJww(QObject::tr("Jww %1").arg("(*.jww)"));
RS_DEBUG->print("fDxfrw: %s", fDxfrw.toLatin1().data());
RS_DEBUG->print("fDxf1: %s", fDxf1.toLatin1().data());
RS_DEBUG->print("fCxf: %s", fCxf.toLatin1().data());
RS_DEBUG->print("fJww: %s", fJww.toLatin1().data());
QString fn = "";
bool cancel = false;
QFileDialog* fileDlg = new QFileDialog(parent, "File Dialog");
QStringList filters;
filters.append(fDxfrw);
filters.append(fDxf1);
filters.append(fLff);
filters.append(fCxf);
filters.append(fJww);
fileDlg->setNameFilters(filters);
fileDlg->setFileMode(QFileDialog::ExistingFile);
fileDlg->setWindowTitle(QObject::tr("Open Drawing"));
fileDlg->setDirectory(defDir);
fileDlg->selectNameFilter(defFilter);
/** preview RVT PORT preview is currently not supported by QT4
RS_Graphic* gr = new RS_Graphic;
QG_GraphicView* prev = new QG_GraphicView(parent);
prev->setContainer(gr);
prev->setBorders(1, 1, 1, 1);
fileDlg->setContentsPreviewEnabled(true);
fileDlg->setContentsPreview(prev, prev);
*/
if (fileDlg->exec()==QDialog::Accepted) {
QStringList fl = fileDlg->selectedFiles();
if (!fl.isEmpty())
fn = fl[0];
fn = QDir::toNativeSeparators( QFileInfo(fn).absoluteFilePath() );
if (type!=NULL) {
if (fileDlg->selectedNameFilter()==fDxf1) {
*type = RS2::FormatDXF1;
} else if (fileDlg->selectedNameFilter()==fDxfrw) {
*type = RS2::FormatDXFRW;
} else if (fileDlg->selectedNameFilter()==fCxf) {
*type = RS2::FormatCXF;
} else if (fileDlg->selectedNameFilter()==fJww) {
*type = RS2::FormatJWW;
}
}
cancel = false;
} else {
cancel = true;
}
// store new default settings:
if (!cancel) {
RS_SETTINGS->beginGroup("/Paths");
RS_SETTINGS->writeEntry("/Open", QFileInfo(fn).absolutePath());
RS_SETTINGS->writeEntry("/OpenFilter", fileDlg->selectedFilter());
RS_SETTINGS->endGroup();
}
RS_DEBUG->print("QG_FileDialog::getOpenFileName: fileName: %s", fn.toLatin1().data());
RS_DEBUG->print("QG_FileDialog::getOpenFileName: OK");
// RVT PORT delete prev;
// RVT PORT delete gr;
delete fileDlg;
return fn;
}
示例4: getSaveFileName
/**
* Shows a dialog for choosing a file name. Saving the file is up to
* the caller.
*
* @param type Will contain the file type that was chosen by the user.
* Can be NULL to be ignored.
*
* @return File name with path and extension to determine the file type
* or an empty string if the dialog was cancelled.
*/
QString QG_FileDialog::getSaveFileName(QWidget* parent, RS2::FormatType* type) {
// read default settings:
RS_SETTINGS->beginGroup("/Paths");
QString defDir = RS_SETTINGS->readEntry("/Save",
RS_SYSTEM->getHomeDir());
QString defFilter = RS_SETTINGS->readEntry("/SaveFilter",
"Drawing Exchange DXF 2007 (*.dxf)");
//QString defFilter = "Drawing Exchange (*.dxf)";
RS_SETTINGS->endGroup();
// prepare file save as dialog:
QFileDialog* fileDlg = new QFileDialog(parent,"Save as");
QStringList filters;
bool done = false;
bool cancel = false;
QString fn = "";
filters.append("Drawing Exchange DXF 2007 (*.dxf)");
filters.append("Drawing Exchange DXF 2004 (*.dxf)");
filters.append("Drawing Exchange DXF 2000 (*.dxf)");
filters.append("Drawing Exchange DXF R14 (*.dxf)");
filters.append("Drawing Exchange DXF R12 (*.dxf)");
filters.append("LFF Font (*.lff)");
filters.append("Font (*.cxf)");
filters.append("JWW (*.jww)");
fileDlg->setNameFilters(filters);
fileDlg->setFileMode(QFileDialog::AnyFile);
fileDlg->setWindowTitle(QObject::tr("Save Drawing As"));
fileDlg->setDirectory(defDir);
fileDlg->setAcceptMode(QFileDialog::AcceptSave);
fileDlg->selectNameFilter(defFilter);
// run dialog:
do {
// accepted:
if (fileDlg->exec()==QDialog::Accepted) {
QStringList fl = fileDlg->selectedFiles();
if (!fl.isEmpty())
fn = fl[0];
fn = QDir::toNativeSeparators( QFileInfo(fn).absoluteFilePath() );
cancel = false;
// append default extension:
// TODO, since we are starting to suppor tmore extensions, we need to find a better way to add the default
if (QFileInfo(fn).fileName().indexOf('.')==-1) {
if (fileDlg->selectedNameFilter()=="LFF Font (*.lff)") {
fn+=".lff";
} else if (fileDlg->selectedNameFilter()=="Font (*.cxf)") {
fn+=".cxf";
} else {
fn+=".dxf";
}
}
// set format:
if (type) {
if (fileDlg->selectedNameFilter()=="LFF Font (*.lff)") {
*type = RS2::FormatLFF;
} else if (fileDlg->selectedNameFilter()=="Font (*.cxf)") {
*type = RS2::FormatCXF;
} else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF 2004 (*.dxf)") {
*type = RS2::FormatDXFRW2004;
} else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF 2000 (*.dxf)") {
*type = RS2::FormatDXFRW2000;
} else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF R14 (*.dxf)") {
*type = RS2::FormatDXFRW14;
} else if (fileDlg->selectedNameFilter()=="Drawing Exchange DXF R12 (*.dxf)") {
*type = RS2::FormatDXFRW12;
} else if (fileDlg->selectedNameFilter()=="JWW (*.jww)") {
*type = RS2::FormatJWW;
} else {
*type = RS2::FormatDXFRW;
}
}
#if !defined (_WIN32) && !defined (__APPLE__)
// overwrite warning:
if(QFileInfo(fn).exists()) {
int choice =
QMessageBox::warning(parent, QObject::tr("Save Drawing As"),
QObject::tr("%1 already exists.\n"
"Do you want to replace it?")
.arg(fn),
QMessageBox::Yes | QMessageBox::No | QMessageBox::Cancel,QMessageBox::Cancel);
switch (choice) {
case QMessageBox::Yes:
//.........这里部分代码省略.........
示例5: getSaveFileName
QString QmitkToFRecorderWidget::getSaveFileName(mitk::ToFImageWriter::ToFImageType& tofImageType,
bool& distanceImageSelected,
bool& amplitudeImageSelected,
bool& intensityImageSelected,
bool& rgbImageSelected,
bool& rawDataSelected,
QWidget *parent,
const QString &caption,
const QString &dir,
const QString &filter,
QString *selectedFilter,
QFileDialog::Options options
)
{
QString selectedFileName = "";
QComboBox* combo = new QComboBox;
combo->addItem("3D");
combo->addItem("2D + t");
QHBoxLayout* checkBoxGroup = new QHBoxLayout();
QCheckBox* distanceImageCheckBox = new QCheckBox;
distanceImageCheckBox->setText("Distance image");
distanceImageCheckBox->setChecked(distanceImageSelected);
QCheckBox* amplitudeImageCheckBox = new QCheckBox;
amplitudeImageCheckBox->setText("Amplitude image");
amplitudeImageCheckBox->setChecked(amplitudeImageSelected);
QCheckBox* intensityImageCheckBox = new QCheckBox;
intensityImageCheckBox->setText("Intensity image");
intensityImageCheckBox->setChecked(intensityImageSelected);
QCheckBox* rgbImageCheckBox = new QCheckBox;
rgbImageCheckBox->setText("RGB image");
rgbImageCheckBox->setChecked(rgbImageSelected);
QCheckBox* rawDataCheckBox = new QCheckBox;
rawDataCheckBox->setText("Raw data");
rawDataCheckBox->setChecked(false);
rawDataCheckBox->setEnabled(false);
checkBoxGroup->addWidget(distanceImageCheckBox);
checkBoxGroup->addWidget(amplitudeImageCheckBox);
checkBoxGroup->addWidget(intensityImageCheckBox);
checkBoxGroup->addWidget(rgbImageCheckBox);
checkBoxGroup->addWidget(rawDataCheckBox);
QFileDialog* fileDialog = new QFileDialog(parent, caption, dir, filter);
QLayout* layout = fileDialog->layout();
QGridLayout* gridbox = qobject_cast<QGridLayout*>(layout);
if (gridbox)
{
gridbox->addWidget(new QLabel("ToF-Image type:"));
gridbox->addWidget(combo);
int lastRow = gridbox->rowCount();
gridbox->addLayout(checkBoxGroup, lastRow, 0, 1, -1);
}
fileDialog->setLayout(gridbox);
fileDialog->setAcceptMode(QFileDialog::AcceptSave);
if (selectedFilter)
{
fileDialog->selectNameFilter(*selectedFilter);
}
if (fileDialog->exec() == QDialog::Accepted)
{
if (selectedFilter)
{
*selectedFilter = fileDialog->selectedFilter();
}
if (combo->currentIndex() == 0)
{
tofImageType = mitk::ToFImageWriter::ToFImageType3D;
}
else
{
tofImageType = mitk::ToFImageWriter::ToFImageType2DPlusT;
}
distanceImageSelected = distanceImageCheckBox->isChecked();
amplitudeImageSelected = amplitudeImageCheckBox->isChecked();
intensityImageSelected = intensityImageCheckBox->isChecked();
rgbImageSelected = rgbImageCheckBox->isChecked();
rawDataSelected = rawDataCheckBox->isChecked();
selectedFileName = fileDialog->selectedFiles().value(0);
}
delete fileDialog;
return selectedFileName;
}