Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
QFileDialog prevent user from overriding file filter
Dimi last edited by Dimi
I have a QFileDialog used like:
fileName = QFileDialog::getOpenFileName(this, tr("Open Image"), "/home/jana", tr("Image Files (*.png *.jpg *.bmp)"));
This filters and shows only image files which is all good and nice. However, the user is still allowed to override this by typing "*" in the filename field and pressing enter. By looking at the documentation there isn't a suitable signal I can connect to and filter or deny that input. Any suggestions how to prevent the user from overriding the file filter and showing other non image files?
JonB last edited by JonB
QFileDialog::filterSelected(const QString &filter) might? But may only be if user selects a filter, not types into field, I don't know? You would have to use a
QFileDialoginstance to use that.
Really you mostly want to check the returned filename for acceptability rather than worrying about what filter the user may or may not use.
Dimi last edited by
Instancing QFileDialog or creating my own is not a problem. I tried all signals and filterSelected is when a user selects a filter, not types (as you suspected). I was just wondering if there's any way not to show at any file types that shouldn't be accepted. Checking the output afterwards is a good enough solution. Thank you for the suggestion!
fadu last edited by
@Dimi you can check file after open file dialog finished
If file end with.jpg .png etc....