QFileDialog: choose directories only but show files as well
-
@michelson
Ok. I understand.
Not sure how you can make it show the files but only
allow to press ok on folder. Not in any easy way.It is not an option to let the user also select a file and just snag the path from it ?
-
@michelson
Well there is a lot of flags. But there is not one that sounds like such function.
(in my head)
You could make your own dialog but that
somewhat a lot of work to NOT select a file.You could also make it 2 step.
First select folder
Then dialog comes with all files , each checked and u can exclude some if needed
or else press ok to proceed.
That way is 100% want you want and serves a function. -
QFileDialog dialog; dialog.setFileMode(QFileDialog::DirectoryOnly); dialog.setOption(QFileDialog::ShowDirsOnly, false); dialog.exec(); qDebug() << dialog.directory();
-
@Hamed.Masafi
Hi
it looks good but its not showing files here on win 7.
Only the dirs.
On your platform, it does show all files also? -
@mrjj said:
Hi
it looks good but its not showing files here on win 7.
Only the dirs.
On your platform, it does show all files also?Hi, on my platform (debian + kde) works well. But we can take a test.
Please change second line to flowing code and test again.dialog.setFileMode(QFileDialog::Directory);
-
@Hamed.Masafi
Ok, must be different on win
Hmm am i blind or is that same line? -
Oh, sorry. My mistake
dialog.setFileMode(QFileDialog::Directory);
-
@Hamed.Masafi
Unfortunetly i can confirm @mrjj issiue - Win7 OS still couses files to be invisible. I guess problem cant be solved easily @ Win OS - i think the only way is to reimplementQFileDialog
which for me is just not worth the time it will take for such trivial thing. -
I've tested on windows. It seems the only possible solution is to ignore native dialog.
QFileDialog dialog; dialog.setFileMode(QFileDialog::DirectoryOnly); dialog.setOption(QFileDialog::DontUseNativeDialog, true); dialog.setOption(QFileDialog::ShowDirsOnly, false); dialog.exec(); qDebug() << dialog.directory();