Important: Please read the Qt Code of Conduct -

qsortfilterproxymodel expand parent items

  • Where is the best place to handle expanding a filtered child's parent using a qsortfilterproxymodel?

    I'm just using the filterAcceptsRow in my proxy model. So far I tried to emit a custom signal in my proxy and connect it with the views expand function. This sorta works, but once a filtered item is found and the reg expression changes i get a stack overflow of a endless loop between my signal and filterAcceptsRow.

  • Lifetime Qt Champion


    When are you emitting that signal ?
    Why are you trying to expand the node while filtering ?

  • Hi SGaist,

    I tried to emit it right before the return of a True bool in the filterAccetpsRow.

    Well that was my first question, where is the best place to expand the parent node on a filtered item? The hierarchy can be a few leafs deep, so I'd like the user to see the expanded tree to the found item.

    I'm pretty sure during the recursive loop of the filterAcceptsRow is the wrong place. I was hoping there might be a filteringFinished signal or something once the filters is done.

  • filterAcceptRow() is definitely the wrong place since it is called for every row, and you only need to expand once.

    Do you have a function that enables/disables filtering? Then I would expand the tree there before enabling the filter.

  • yep, I definitely only would like to call this once.

    I think i found a compromise, I connected the editingFinished signal on the lineedit, so when the user filters it might show a parent, indicating that there is data found, but not expanded. This gives the the opportunity to write the full name or correct mistakes without any calls each text change. The down side is maybe the user doesn't know the names that might be similar and need to see all the options to complete the name filter.

    When the user presses enter, I can do one recursion to expand the proxy model on any rows left. I dont like having mystery gui logic like this, but I dont want to make a science project out of this... unless someone else has a better approach?

Log in to reply