/*****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(); }
时间: 2024-10-07 08:49:29