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();
    }
  • 相关阅读:
    子类继承方法的重写
    操作系统的用户模式和内核模式
    Java中的CAS
    FaceBook SDK登录功能实现(Eclipse)
    eclipse集成ijkplayer项目
    android handler传递数据
    android发送短信
    hadoop中的job.setOutputKeyClass与job.setMapOutputKeyClass
    mysql对事务的支持
    使用jd-gui+javassist修改已编译好的class文件
  • 原文地址:https://www.cnblogs.com/qnkk123/p/6704461.html
Copyright © 2011-2022 走看看