QFileDialog: how to choice File or Directory in the same Dialog
Hallo!
Can I coice a File or a Directory in the same file dialog?
QFileDialog fd(this);
fd.setFileMode( QFileDialog::Directory); //I can choice only directories
fd.setFileMode( QFileDialog::AnyFile); //If I select the directory and press Ok, i don't leave the Dialog but go to this directory:confused:
Re: QFileDialog: how to choice File or Directory in the same Dialog
It would be hard to create a combined directory and file dialog. Much because it would be impossible to tell if you pick a directory or just want so enter it to look for other directories or files.
Re: QFileDialog: how to choice File or Directory in the same Dialog
My idee is to change to the directory by pressing Enter or clicking (Focus on the directory) and to pick a directory or a file with the Pushbutton Ok (Clickingwith the mouse on the pushbutton or pressing Enter as the focus is on the pushbutton).
Re: QFileDialog: how to choice File or Directory in the same Dialog
You can use QDirModel to implement your own file chooser or subclass QFileDialog and change it according to your needs.
Re: QFileDialog: how to choice File or Directory in the same Dialog
Quote:
Originally Posted by illojal
i found a thread where you needed QFileDialog to being able to select files and dirs and im in the exact same situation now so i wonder if you ever made such a dialog. I would be really glad if you could share it with me.
BUFileDia.h
#ifndef _BUFILEDIALOG_H_
#define _BUFILEDIALOG_H_
#include <QFileDialog>
class BUFileDialog: public QFileDialog
{
public:
BUFileDialog ( QWidget * parent, Qt::WindowFlags flags ):QFileDialog(parent,flags){}
BUFileDialog ( QWidget * parent = 0, const QString & caption = QString(), const QString & directory = QString(), const QString & filter = QString() ):
QFileDialog ( parent ,caption,directory,filter){}
public slots:
void accept ();
};
#endif
BUFileDia.cpp
#include "BUFileDialog.h"
void BUFileDialog::accept()
{
QStringList files = selectedFiles();
if (files.isEmpty())
return;
emit filesSelected(files);
QDialog::accept();
}