• Qt中的QFileDialog类的几个示范代码


    void Dialog::setExistingDirectory()
    {  //选择一个文件夹;
        QFileDialog::Options options = QFileDialog::DontResolveSymlinks | QFileDialog::ShowDirsOnly;
        if (!native->isChecked())
            options |= QFileDialog::DontUseNativeDialog;
        QString directory = QFileDialog::getExistingDirectory(this,
                                    tr("QFileDialog::getExistingDirectory()"),
                                    directoryLabel->text(),
                                    options);
        if (!directory.isEmpty())
            directoryLabel->setText(directory);
    }

    void Dialog::setOpenFileName()
    {  //打开一个文件;
        QFileDialog::Options options;
        if (!native->isChecked())
            options |= QFileDialog::DontUseNativeDialog;
        QString selectedFilter;
        QString fileName = QFileDialog::getOpenFileName(this,
                                    tr("QFileDialog::getOpenFileName()"),
                                    openFileNameLabel->text(),
                                    tr("All Files (*);;Text Files (*.txt)"),
                                    &selectedFilter,
                                    options);
        if (!fileName.isEmpty())
            openFileNameLabel->setText(fileName);
    }

    void Dialog::setOpenFileNames()
    {  //打开多个文件;
        QFileDialog::Options options;
        if (!native->isChecked())
            options |= QFileDialog::DontUseNativeDialog;
        QString selectedFilter;
        QStringList files = QFileDialog::getOpenFileNames(
                                    this, tr("QFileDialog::getOpenFileNames()"),
                                    openFilesPath,
                                    tr("All Files (*);;Text Files (*.txt)"),
                                    &selectedFilter,
                                    options);
        if (files.count()) {
            openFilesPath = files[0];
            openFileNamesLabel->setText(QString("[%1]").arg(files.join(", ")));
        }
    }

    void Dialog::setSaveFileName()
    {  //保存一个文件;
        QFileDialog::Options options;
        if (!native->isChecked())
            options |= QFileDialog::DontUseNativeDialog;
        QString selectedFilter;
        QString fileName = QFileDialog::getSaveFileName(this,
                                    tr("QFileDialog::getSaveFileName()"),
                                    saveFileNameLabel->text(),
                                    tr("All Files (*);;Text Files (*.txt)"),
                                    &selectedFilter,
                                    options);
        if (!fileName.isEmpty())
            saveFileNameLabel->setText(fileName);
    }

  • 相关阅读:
    如何用C#在Excel中生成图表?
    SQL2000怎样可以让一个数据库用几个磁盘分区
    用C#快速往Excel写数据
    SQL语句导入导出大全
    js解密
    Word的常用操作
    网页javascript获得当前页面或窗口的各个宽度高度
    用C#动态创建Access数据库
    MSSQL一些精典语句
    寻找Vista下PC硬件驱动
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175733.html
Copyright © 2020-2023  润新知