PDA

View Full Version : Customize QFileDialog



Swankee
19th November 2009, 23:13
I have my FileDialog here:

QFileDialog box;
QStringList fileNames;

box.setFileMode(QFileDialog::ExistingFile);
if (box.exec())
{
fileNames = box.selectedFiles();
}

It works on a button click just fine. Am I able to streamline what it looks like? I'm not interested in having the user open or choose files but rather just view that files are present. Really what would be perfect would be a windows explorer type window where I could view files / not only the directories. Is there anything out there for what I've described? thanks!

wysota
20th November 2009, 08:53
QFileSystemModel and QTableView or QTreeView.

Swankee
20th November 2009, 15:11
QFileSystemModel and QTableView or QTreeView.

Cool, thank you!

Here's what I came up with, but why does it launch so slow (~10 seconds) when I try to display all drives ("\\"). It's as fast as you would expect when you only choose "C:\\"


QSplitter *splitter = new QSplitter;
QDirModel *model = new QDirModel;
model->setFilter( QDir::AllEntries | QDir::NoDotAndDotDot ) ;
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);

tree->setRootIndex(model->index( "\\" ));

splitter->setWindowTitle("Quick Look");
splitter->show();

Swankee
23rd November 2009, 14:37
Cool, thank you!

Here's what I came up with, but why does it launch so slow (~10 seconds) when I try to display all drives ("\\").


QSplitter *splitter = new QSplitter;
QDirModel *model = new QDirModel;
model->setFilter( QDir::AllEntries | QDir::NoDotAndDotDot ) ;
QTreeView *tree = new QTreeView(splitter);
tree->setModel(model);

tree->setRootIndex(model->index( "\\" ));

splitter->setWindowTitle("Quick Look");
splitter->show();

Can anyone lend a hand?

thanks!

wysota
23rd November 2009, 19:49
Because QDirModel is slow. Contrary to QFileSystemModel.

Swankee
23rd November 2009, 22:37
Good to know.

Would you mind assisting with a piece of code?

wysota
23rd November 2009, 23:02
Try and see.

Swankee
24th November 2009, 17:15
Here's what I was able to come up with but it's not displaying on click. It compiles but it doesnt' work. Could you help me get it to display?



QFileSystemModel *model = new QFileSystemModel(this);
model->setResolveSymlinks(true);
QModelIndex root = model->setRootPath(QDir::rootPath());
this->setVisible(model);

wysota
24th November 2009, 19:28
this->setVisible(model);
This doesn't make much sense. What do you expect it to do?

Swankee
25th November 2009, 19:51
this->setVisible(model);
This doesn't make much sense. What do you expect it to do?

I ended up getting it working. I thought that would set the model visible, no?

Here it is:

QFileSystemModel *model = new QFileSystemModel;
model->setRootPath("");
QTreeView *tree = new QTreeView();
tree->setModel(model);

QString title("Quick Look");
tree->setWindowTitle(title);

tree->show();

wysota
25th November 2009, 20:21
Model is just a concept, it can't be made "visible".