Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6638843
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T23:29:06+00:00 2026-05-25T23:29:06+00:00

I have a working tree model derived from QAbstractItemModel and I wish to filter

  • 0

I have a working tree model derived from QAbstractItemModel and I wish to filter it using a QSortFilterProxyModel subclass to display only children nodes of certain criteria. For example I have the following tree:

A
- B
-- C1
-- C1
-- C1
--- C2
- D
- E

I want to filter this tree with the condition that the node has name == C1 and display only the nodes with C1 and their children like this:

C1
C1
C1
- C2

I already have a subclass with filterAcceptsRow() re-implemented that can partially do what I want but it will still show the parent and grandparent of C1 nodes:

A
- B
-- C1
-- C1
-- C1
--- C2

I think this is because for children nodes to even be considered, their parent has to pass the filterAcceptsRow() test, am I right? How can I implement filterAcceptRows() or other methods such that it can do what I have described?

I have asked this question sometime back in qtcentre and qtforum but did not get any useful reply. I tried to move the indices of the QSortFilterProxyModel subclass directly using beginMoveRows and endMoveRows inside filterAcceptsRow() but that just crashes the test application due to dangerous const_cast.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T23:29:07+00:00Added an answer on May 25, 2026 at 11:29 pm

    Okay, I’ve found a solution to my problem. Just use QTreeView::setRootIndex() with index B as the input argument. Index B becomes the root index of the QTreeView, which is hidden and only its children are shown in full.

    I felt really dumb after finding this solution. Guess I was too focused on using the proxy model to modify how the data is presented, I had totally forgotten about QTreeView.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have edits to my working tree which I would like to continue working
I'm working on building a tree structure in MySQL and have been experimenting with
I'm working on UVa #112 Tree Summing . I have what I think should
I have been working with Visual Studio (WinForm and ASP.NET applications using mostly C#)
I have been working with a string[] array in C# that gets returned from
I have a working copy of my project, checked out using Subversion 1.5.1. When
I have a working LINQ to SQL model. I want to be able to
I have following working tree state $ git status foo/bar.txt # On branch master
I have a dirty working tree, dirty because I made changes to source files
I am working on a small game using webgl. Within this game I have

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.