Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to disable filtering option for a QTreeView or Model?
Forum Updated to NodeBB v4.3 + New Features

How to disable filtering option for a QTreeView or Model?

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtreeviewmodel-view
4 Posts 2 Posters 2.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • N Offline
    N Offline
    NIXIN
    wrote on 23 Jun 2016, 05:38 last edited by
    #1

    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???

    R 1 Reply Last reply 23 Jun 2016, 06:37
    0
    • N NIXIN
      23 Jun 2016, 05:38

      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???

      R Offline
      R Offline
      raven-worx
      Moderators
      wrote on 23 Jun 2016, 06:37 last edited by
      #2

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

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      N 1 Reply Last reply 24 Jun 2016, 11:09
      0
      • R raven-worx
        23 Jun 2016, 06:37

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

        N Offline
        N Offline
        NIXIN
        wrote on 24 Jun 2016, 11:09 last edited by
        #3

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

        R 1 Reply Last reply 24 Jun 2016, 11:27
        0
        • N NIXIN
          24 Jun 2016, 11:09

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

          R Offline
          R Offline
          raven-worx
          Moderators
          wrote on 24 Jun 2016, 11:27 last edited by
          #4

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

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          1

          1/4

          23 Jun 2016, 05:38

          • Login

          • Login or register to search.
          1 out of 4
          • First post
            1/4
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved