zoukankan      html  css  js  c++  java
  • 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);
    }

  • 相关阅读:
    游戏UI框架设计(三) : 窗体的层级管理
    游戏UI框架设计(二) : 最简版本设计
    游戏UI框架设计(一) : 架构设计理论篇
    天启:如何从零开始建设数据中台? | 数智加速度04课回顾
    何夕:数据战略不仅是技术问题,更是业务和组织问题 | 数智加速度03课回顾
    才言:中台战略下,企业组织如何顺应商业变迁 | 数智加速度02回顾
    行在:数据中台的最终目的是给企业带来降本增效 | 数智加速度01课回顾
    腰部零售企业需要数据中台吗?
    硬核直播 | 全面解析数据中台,点燃「数智加速度」
    南京新百 × 奇点云 | 老字号百货购物中心运营的数智化转型破局
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175733.html
Copyright © 2011-2022 走看看