Important: Please read the Qt Code of Conduct -

How to disable filtering option for a QTreeView or Model?

  • I am having a piece of code which deals with two QTreeView, where the items are added from left tree view to the right tree view. Here is a part of code:

    MasterModel *model = new MasterModel;
    LeftProxyFilterModel *leftModel = new LeftProxyFilterModel;
    RightSelectedRowsFiletrModel *rightModel = new RightSelectedRowsFilterModel;

    QTreeView *leftTreeView;
    QTreeView *rightTreeView;



    Now for filtering some strings are set like this:


    This line is Filtering the contents of both the tree views, what I want is filtering option should be applicable only for left tree view. Can someone help me to achieve this???

  • Moderators

    simply add a method to enable/disable filtering (bool).
    In the filterAcceptsRow() method "return true" when filtering was disabled with your method.

  • @raven-worx How to implement enable/disable filtering(bool)

  • Moderators


    class MySortFilterProxyModel : public QSortFilterProxyModel
        Q_PROPERTY(bool FilterEnabled READ isFilterEnabled WRITE setFilterEnabled )
    virtual bool filterAcceptsRow(int source_row, const QModelIndex & source_parent) const
          if( !m_IsFilterEnabled )
              return true;
          // your filtering code here
    bool isFilterEnabled() const { return m_IsFilterEnabled };
    void setFilterEnabled( bool enabled ) {
         if( m_IsFilterEnabled != enabled )
               m_IsFilterEnabled = enabled;
         bool m_IsFilterEnabled;

Log in to reply