@sandip-nandwana
You are trying to use setNameFilters() to filter the directories/folders shown, is that right? I would not expect that to work in any situation, whether you set it initially or change it? The name filters are intended to be like *.txt to filter the files being shown within each directory, but not for the directory names themselves (else e.g. *.txt would never be useful). Is that your situation?
If so, I think you need to find another approach, writing your own filter for directory names. You might interpose a QSortFilterProxyModel for this. There is an example in the accepted solutuon at e.g. https://stackoverflow.com/a/56627595/489865. It's a bit old but looks OK, use setFilterRegularExpression() instead of setFilterRegExp().
I am not sure whether that example will mean that your your whole tree will only display the (filtered) directories now, and nothing else. If you have to be smarter I think you will need to: subclass QSortFilterProxyModel, override QSortFilterProxyModel::filterAcceptsRow(), implement your logic there. Use that instead of setting a regular expression filter on the proxy so that you can implement logic to test for the item type to see whether it is a directory or a file, since you want these to behave differently.