Skip to content

Replacing `QDirModel` by `QFilesystemModel`

Looks like the QDirModel has been removed in Qt6 and is considered as 'deprecated' in Qt5 (but without any message).

Here is a short example on how to move to QFileSystemModel and keeping the same behavior most likely:

     def __init__(self, text, parent, filters=None, **kwargs):
         super().__init__(parent=parent, **kwargs)
         self.completer = qt.QCompleter()
-        model = qt.QDirModel(self.completer)
+        self.completer.setCompletionRole(qt.QFileSystemModel.FileNameRole)
+        model = qt.QFileSystemModel(self.completer)
+        model.setRootPath(qt.QDir.currentPath())
         if filters is not None:
             model.setFilter(filters)
         self.completer.setModel(model)