QFileDialog prevent user from overriding file filter
-
wrote on 7 Jan 2022, 12:41 last edited by Dimi 1 Jul 2022, 12:43
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?
-
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?
wrote on 7 Jan 2022, 12:57 last edited by JonB 1 Jul 2022, 12:58@Dimi
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 aQFileDialog
instance 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.
-
wrote on 7 Jan 2022, 13:39 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!
-
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?
1/4