PDA

View Full Version : QFileDialog custom acceptance condition



akos.maroy
3rd April 2011, 17:29
I wonder how it is possible to set a custom acceptance condition for a QFileDialog.

what I want to do is to have a dialog that would only accept directories that have a file of a certain name in them (say, a file named foo.bar). so when the QFileDialog is displayed, the Open button would only be enabled if the directory being selected matches the property of having a file named 'foo.bar' in it.

I looked at the QFileDialog API, but did not find a way to add such a custom test.

any pointers would be appreciated.

ChiliPalmer
4th April 2011, 13:01
How about setNameFilter (http://doc.qt.nokia.com/4.7/qfiledialog.html#setNameFilter) ?
Sure, that way files not matching your filename wouldn't even be shown, but, from the users point of view, wouldn't it be better not to show files the user can't chose, instead of having him click around until he happens on such a file?

akos.maroy
4th April 2011, 13:24
How about setNameFilter (http://doc.qt.nokia.com/4.7/qfiledialog.html#setNameFilter) ?
Sure, that way files not matching your filename wouldn't even be shown, but, from the users point of view, wouldn't it be better not to show files the user can't chose, instead of having him click around until he happens on such a file?

well, the problem comes from that I don't want to filter for the file name - I want to be able to select directories, which contain a specific file. the name of the directory is irrelevant.

ChiliPalmer
4th April 2011, 13:35
Oh, I see. Have a look at this (http://doc.qt.nokia.com/4.7/itemviews-customsortfiltermodel.html). You could use such a filter with your file dialog.