当前位置: 首页>>代码示例>>C++>>正文


C++ QFileDialog::selectFilter方法代码示例

本文整理汇总了C++中QFileDialog::selectFilter方法的典型用法代码示例。如果您正苦于以下问题:C++ QFileDialog::selectFilter方法的具体用法?C++ QFileDialog::selectFilter怎么用?C++ QFileDialog::selectFilter使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在QFileDialog的用法示例。


在下文中一共展示了QFileDialog::selectFilter方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: saveToFile

void ReportEditWidget::saveToFile()
{
    QFileDialog dlg;
    dlg.setAcceptMode(QFileDialog::AcceptSave);
    dlg.setFileMode(QFileDialog::AnyFile);
    dlg.setViewMode(QFileDialog::List);

    QStringList filters;
    filters << tr("All reports (*.xml *.ncr *.ods)");
    filters << tr("NcReport (*.ncr)");
    filters << tr("CuteReport (*.xml)");
    filters << tr("OO Calc (*.ods)");
    filters << tr("All files (*.*)");
    dlg.setNameFilters(filters);

    QString ext;
    int type = ui->cmbType->currentKey().toInt();
    switch (type) {
    case Report::NcReportEngine :
        ext = ".ncr";
        dlg.selectFilter(filters.at(1));
        break;
    case Report::CuteReportEngine :
        ext = ".xml";
        dlg.selectFilter(filters.at(2));
        break;
    case Report::OpenOfficeEngine :
        ext = ".ods";
        dlg.selectFilter(filters.at(3));
        break;
    default:
        break;
    }

    dlg.selectFile(ui->edName->text() + ext);
    if (dlg.exec() == QDialog::Accepted) {
        QFile f(dlg.selectedFiles().first());
        if (!f.open(QIODevice::WriteOnly)) {
            QMessageBox::critical(this, tr("Save"), f.errorString());
            return;
        }

        f.write(m_data.toUtf8());
        f.close();
    }
}
开发者ID:wulff007,项目名称:Veda,代码行数:46,代码来源:reporteditwidget.cpp

示例2: QFileDialog

void
pfmPage::slotPFMFileBrowse ()
{
    QStringList         files, filters;
    QString             file;


    QFileDialog *fd = new QFileDialog (this, tr ("pfmLoadM Open PFM Structure"));
    fd->setViewMode (QFileDialog::List);


    //  Always add the current working directory and the last used directory to the sidebar URLs in case we're running from the command line.
    //  This function is in the nvutility library.

    setSidebarUrls (fd, pfm_global->output_dir);


    filters << tr ("PFM (*.pfm)");

    fd->setFilters (filters);
    fd->setFileMode (QFileDialog::AnyFile);
    fd->selectFilter (tr ("PFM (*.pfm)"));

    if (fd->exec () == QDialog::Accepted)
    {
        //  Save the directory that we were in when we selected a file.

        pfm_global->output_dir = fd->directory ().absolutePath ();

        files = fd->selectedFiles ();

        pfm_def->name = files.at (0);


        if (!pfm_def->name.isEmpty())
        {
            if (!pfm_def->name.endsWith (".pfm")) pfm_def->name.append (".pfm");


            //  This will trigger slotPFMFileEdit.

            pfm_file_edit->setText (pfm_def->name);
        }
    }
}
开发者ID:schwehr,项目名称:pfmabe,代码行数:45,代码来源:pfmPage.cpp

示例3: fd

void
pfmPage::slotAreaFileBrowse ()
{
    QFileDialog fd (this, tr ("pfmLoadM Area File"));
    fd.setViewMode (QFileDialog::List);


    //  Always add the current working directory and the last used directory to the sidebar URLs in case we're running from the command line.
    //  This function is in the nvutility library.

    setSidebarUrls (&fd, pfm_global->area_dir);


    QStringList filters;
    filters << tr ("Area file (*.ARE *.are *.afs)");

    fd.setFilters (filters);
    fd.setFileMode (QFileDialog::ExistingFile);
    fd.selectFilter (tr ("Area file (*.ARE *.are *.afs)"));


    QStringList files;
    if (fd.exec () == QDialog::Accepted)
    {
        //  Save the directory that we were in when we selected a file.

        pfm_global->area_dir = fd.directory ().absolutePath ();

        files = fd.selectedFiles ();

        pfm_def->area = files.at (0);


        if (!pfm_def->area.isEmpty())
        {
            area_edit->setText (pfm_def->area);

            if (!pfm_file_edit->text ().isEmpty () && !area_edit->text ().isEmpty ()) setButtonText (QWizard::NextButton, tr ("Next"));
        }
    }
}
开发者ID:schwehr,项目名称:pfmabe,代码行数:41,代码来源:pfmPage.cpp

示例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->setFilters(filters);
    fileDlg->setFileMode(QFileDialog::AnyFile);
    fileDlg->setWindowTitle(QObject::tr("Save Drawing As"));
    fileDlg->setDirectory(defDir);
    fileDlg->setAcceptMode(QFileDialog::AcceptSave);
    fileDlg->selectFilter(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->selectedFilter()=="LFF Font (*.lff)") {
                    fn+=".lff";
                } else if (fileDlg->selectedFilter()=="Font (*.cxf)") {
                        fn+=".cxf";
                } else {
                    fn+=".dxf";
                }
            }

            // set format:
            if (type!=NULL) {
                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:
                    done = true;
                    break;
//.........这里部分代码省略.........
开发者ID:tianqizi,项目名称:LibreCAD,代码行数:101,代码来源:qg_filedialog.cpp

示例5: getOpenFileNames


//.........这里部分代码省略.........
    QEventLoop loop;

    QString startWith = QDir::toNativeSeparators (aStartWith);
    LoopObject loopObject ((QEvent::Type) GetOpenFileNameEvent::TypeId, loop);

    if (aParent)
        aParent->setWindowModality (Qt::WindowModal);

    Thread openDirThread (aParent, &loopObject, startWith, aFilters, aCaption);
    openDirThread.start();
    loop.exec();
    openDirThread.wait();

    if (aParent)
        aParent->setWindowModality (Qt::NonModal);

    return QStringList() << loopObject.result();

#elif defined (VBOX_WS_X11) && (QT_VERSION < 0x040400)

    /* Here is workaround for Qt4.3 bug with QFileDialog which crushes when
     * gets initial path as hidden directory if no hidden files are shown.
     * See http://trolltech.com/developer/task-tracker/index_html?method=entry&id=193483
     * for details */
    QFileDialog dlg (aParent);
    dlg.setWindowTitle (aCaption);
    dlg.setDirectory (aStartWith);
    dlg.setFilter (aFilters);
    if (aSingleFile)
        dlg.setFileMode (QFileDialog::ExistingFile);
    else
        dlg.setFileMode (QFileDialog::ExistingFiles);
    if (aSelectedFilter)
        dlg.selectFilter (*aSelectedFilter);
    dlg.setResolveSymlinks (aResolveSymlinks);
    QAction *hidden = dlg.findChild <QAction*> ("qt_show_hidden_action");
    if (hidden)
    {
        hidden->trigger();
        hidden->setVisible (false);
    }
    return dlg.exec() == QDialog::Accepted ? dlg.selectedFiles() : QStringList() << QString::null;

#elif defined (VBOX_WS_MAC) && (QT_VERSION >= 0x040600) && (QT_VERSION < 0x050000)

    /* After 4.5 exec ignores the Qt::Sheet flag.
     * See "New Ways of Using Dialogs" in http://doc.trolltech.com/qq/QtQuarterly30.pdf why.
     * We want the old behavior for file-save dialog. Unfortunately there is a bug in Qt 4.5.x
     * which result in showing the native & the Qt dialog at the same time. */
    QFileDialog dlg(aParent);
    dlg.setWindowTitle(aCaption);

    /* Some predictive algorithm which seems missed in native code. */
    QDir dir(aStartWith);
    while (!dir.isRoot() && !dir.exists())
        dir = QDir(QFileInfo(dir.absolutePath()).absolutePath());
    const QString strDirectory = dir.absolutePath();
    if (!strDirectory.isNull())
        dlg.setDirectory(strDirectory);
    if (strDirectory != aStartWith)
        dlg.selectFile(QFileInfo(aStartWith).absoluteFilePath());

    dlg.setNameFilter(aFilters);
    if (aSingleFile)
        dlg.setFileMode(QFileDialog::ExistingFile);
    else
开发者ID:svn2github,项目名称:virtualbox,代码行数:67,代码来源:QIFileDialog.cpp

示例6: slotTxtFileBrowse

void mosaicPage::slotTxtFileBrowse ()
{
  QStringList         files, filters;
  QString             file;


  QFileDialog *fd = new QFileDialog (this, tr ("pfmChartsImage Select Mission Parameters File"));
  fd->setViewMode (QFileDialog::List);


  //  Always add the current working directory and the last used directory to the sidebar URLs in case we're running from the command line.
  //  This function is in the nvutility library.

  setSidebarUrls (fd, options->param_dir);


  filters << tr ("Text (*.txt)");

  fd->setFilters (filters);
  fd->setFileMode (QFileDialog::ExistingFile);
  fd->selectFilter (tr ("Text (*.txt)"));

  if (fd->exec () == QDialog::Accepted)
    {
      files = fd->selectedFiles ();

      QString txt_file_name = files.at (0);


      if (!txt_file_name.isEmpty())
        {
          txt_file_edit->setText (txt_file_name);

	  NV_CHAR txt_file[512];
	  strcpy (txt_file, txt_file_name.toAscii ());

	  FILE *fp;

	  if ((fp = fopen (txt_file, "r")) == NULL)
	    {
	      QMessageBox::warning (this, tr ("Select Mission Parameters File"),
				    tr ("The file ") + txt_file_name + 
				    tr (" could not be opened.") +
				    tr ("  The error message returned was:\n\n") +
				    QString (strerror (errno)));

              return;
	    }


	  NV_CHAR string[128];
	  NV_FLOAT64 roll_bias = 0.0, pitch_bias = 0.0, heading_bias = 0.0, pixel_size = 0.0, focal_length = 0.0, 
	    col_offset = 0.0, row_offset = 0.0, time_delay = 0.0;
          NV_INT32 ms;

	  while (fgets (string, sizeof (string), fp) != NULL)
	    {
	      if (strstr (string, "camera_boresight_roll:"))
		sscanf (string, "camera_boresight_roll: %lf", &roll_bias);

	      if (strstr (string, "camera_boresight_pitch:"))
		sscanf (string, "camera_boresight_pitch: %lf", &pitch_bias);

	      if (strstr (string, "camera_boresight_heading:"))
		sscanf (string, "camera_boresight_heading: %lf", &heading_bias);

	      if (strstr (string, "pixel_size:"))
		sscanf (string, "pixel_size: %lf", &pixel_size);

	      if (strstr (string, "focal_length:"))
		sscanf (string, "focal_length: %lf", &focal_length);

	      if (strstr (string, "principal_point_offsets:"))
		sscanf (string, "principal_point_offsets: %lf, %lf", &col_offset, &row_offset);

	      if (strstr (string, "camera_trig_delay:"))
                {
                  sscanf (string, "camera_trig_delay: %d", &ms);
                  time_delay = (NV_FLOAT64) ms / 1000.0;
                }
	    }
	  fclose (fp);

	  timeSpin->setValue (time_delay);
	  rollSpin->setValue (roll_bias);
	  pitchSpin->setValue (pitch_bias);
	  headingSpin->setValue (heading_bias);
	  focalSpin->setValue (focal_length);
	  pixelSpin->setValue (pixel_size);
	  colSpin->setValue (col_offset);
	  rowSpin->setValue (row_offset);
        }

      options->param_dir = fd->directory ().absolutePath ();
    }
}
开发者ID:dmagiccys,项目名称:pfmabe,代码行数:96,代码来源:mosaicPage.cpp


注:本文中的QFileDialog::selectFilter方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。