Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I believe what you can do is:</p> <ol> <li>Create a custom proxy model. You can use <a href="http://doc.qt.io/qt-5/qsortfilterproxymodel.html" rel="nofollow noreferrer">QSortFilterProxyModel</a> as a base class for your model; </li> <li>In the proxy model override the <a href="http://doc.qt.io/qt-5/qsortfilterproxymodel.html#filterAcceptsRow" rel="nofollow noreferrer">filterAcceptsRow</a> method and return false for files which have the <em>".backup."</em> word in their names;</li> <li>Set new proxy model to the file dialog: <a href="http://doc.qt.io/qt-5/qfiledialog.html#setProxyModel" rel="nofollow noreferrer">QFileDialog::setProxyModel</a>;</li> </ol> <p>Below is an example:</p> <p>Proxy model:</p> <pre><code>class FileFilterProxyModel : public QSortFilterProxyModel { protected: virtual bool filterAcceptsRow(int source_row, const QModelIndex&amp; source_parent) const; }; bool FileFilterProxyModel::filterAcceptsRow(int sourceRow, const QModelIndex &amp;sourceParent) const { QModelIndex index0 = sourceModel()-&gt;index(sourceRow, 0, sourceParent); QFileSystemModel* fileModel = qobject_cast&lt;QFileSystemModel*&gt;(sourceModel()); return fileModel-&gt;fileName(index0).indexOf(".backup.") &lt; 0; // uncomment to call the default implementation //return QSortFilterProxyModel::filterAcceptsRow(sourceRow, sourceParent); } </code></pre> <p>dialog was created this way:</p> <pre><code>QFileDialog dialog; dialog.setProxyModel(new FileFilterProxyModel); dialog.setNameFilter("XML (*.xml)"); dialog.setOption(QFileDialog::DontUseNativeDialog); dialog.exec(); </code></pre> <p>The proxy model is supported by non-native file dialogs only.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload