zoukankan      html  css  js  c++  java
  • Qt 同时选择文件和文件夹(可多选)

    /*****CFileDialog.h*****/
    
    #ifndef CFILEDIALOG_H
    #define CFILEDIALOG_H
    
    #include <QObject>
    #include <QFileDialog>
    
    class CFileDialog : public QFileDialog
    {
        Q_OBJECT
    public:
        CFileDialog(QWidget *parent = 0);
        ~CFileDialog();
    
    public slots:
        void onChiose();
    };
    
    #endif // CFILEDIALOG_H
    /***********CFileDialog.cpp**********/
    
    #include "CFileDialog.h"
    #include <QListView>
    #include <QTreeView>
    #include <QDialogButtonBox>
    
    CFileDialog::CFileDialog(QWidget *parent)
        : QFileDialog(parent)
    {
        this->setOption(QFileDialog::DontUseNativeDialog,true);
    
        //支持多选
        QListView *pListView = this->findChild<QListView*>("listView");
        if (pListView)
            pListView->setSelectionMode(QAbstractItemView::ExtendedSelection);
        QTreeView *pTreeView = this->findChild<QTreeView*>();
        if (pTreeView)
            pTreeView->setSelectionMode(QAbstractItemView::ExtendedSelection);
        QDialogButtonBox *pButton = this->findChild<QDialogButtonBox *>("buttonBox");
    
        disconnect(pButton, SIGNAL(accepted()), this, SLOT(accept()));//使链接失效
        connect(pButton, SIGNAL(accepted()), this, SLOT(onChiose()));//改成自己的槽
    }
    
    CFileDialog::~CFileDialog()
    {
    
    }
    
    void CFileDialog::onChiose()
    {
        QDialog::accept();
    }
    CFileDialog fileDialog;
    if ( fileDialog.exec() == QDialog::accept())
    {
         qDebug() << fileDialog.selectedFiles();
    }
  • 相关阅读:
    sql语句中字符串分解查询的一种解决方法。
    VMware虚拟机的网络连接
    sql注入
    mvnrepository.com jar包下载
    局部刷新与json
    初涉json
    ios UIKit 基础控件创建与属性
    实用数学函数
    OC中的随机数函数——arc4random()
    OC中关于字符串的操作
  • 原文地址:https://www.cnblogs.com/qnkk123/p/6704461.html
Copyright © 2011-2022 走看看