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;

    leftModel->setSourceModel(model);
    rightModel->setSourceModel(leftModel);

    leftTreeView->setModel(leftModel);
    rightTreeView->setModel(rightModel);

    Now for filtering some strings are set like this:

    leftModel->setFilterWildcard(LineEdit->text());

    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

    @NIXIN
    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

    @NIXIN

    class MySortFilterProxyModel : public QSortFilterProxyModel
    {
        Q_OBJECT
        Q_PROPERTY(bool FilterEnabled READ isFilterEnabled WRITE setFilterEnabled )
    
    public:
    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;
               this->invalidate();
         }
    }
    
    private:
         bool m_IsFilterEnabled;
    

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.