0

With Qt I'd like to open a QFileDialog in which only those files are shown, which contain a space character.

Here is a simple example:

QFileDialog::getOpenFileName(nullptr, "Open file", "/tmp", "My1stFilter (* *);;My2ndFilter (x y)");

However My1stFilter (* *) matches all files while My2ndFilter (y x) matches all files with the name "x" and with the name "y", while I'd like to have only the files with the name "x y". This is not very surprising since the blank usually separates different filter patterns (according to https://doc.qt.io/qt-5/qfiledialog.html#setNameFilter)

Is there a way to escape special characters like a blank in the name-filters of a QFileDialog?
(I have a similar problem with parentheses characters in the name filter.)

I've tried to set a backslash before the blank or putting the whole pattern in single quotes and double quotes without success.

Holger
  • 3,920
  • 1
  • 13
  • 35

1 Answers1

1

You need to forego the native file dialog which simply doesn't support this. Then you can use a proxy model to filter based on your criteria.

See Regular Expression Filter for QFileDialog

ypnos
  • 50,202
  • 14
  • 95
  • 141