View Full Version : QFileDialog: how to choice File or Directory in the same Dialog
VlJE
11th December 2006, 10:40
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:
e8johan
11th December 2006, 19:18
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.
VlJE
12th December 2006, 08:13
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).
wysota
12th December 2006, 10:49
You can use QDirModel to implement your own file chooser or subclass QFileDialog and change it according to your needs.
VlJE
13th June 2007, 15:37
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();
}
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.