QFileDialog.getSaveFileName allows illegal characters to be entered as a path Python3, PyQt5

46 Views Asked by At

In my PyQt5 GUI I use a QFileDialog widget to allow the user to select a file path to save some data to. However, the QFileDialog allows special characters such as commas, &, @, #, etc., to be used in the path/file name. This will cause some obvious problems if I tried to access the file location containing invalid characters. I am looking for a way to prevent the user from entering these characters into the file path field in the first place. Is there a way to stop the QFileDialog widget from accepting these invalid characters BEFORE the QFileDialog widget closes? Is there a way to prevent those characters from appearing in the file path file path field inside the QFileDialog popup widget when the user types them? Please respond with Python code, NOT C++.

0

There are 0 best solutions below