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

  • SEARCH
  • Home
  • 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 1029515
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T12:33:20+00:00 2026-05-16T12:33:20+00:00

I have a reimplemented QSortFilterProxyModel acceptRows to achieve custom behavior, i want it to

  • 0

I have a reimplemented QSortFilterProxyModel acceptRows to achieve custom behavior, i want it to not filter out items which have a valid child.

class KSortFilterProxyModel(QSortFilterProxyModel):
    #FIXME: Funciona pero es endemoniadamente lento
    def __init__(self, parent=None):
        super(KSortFilterProxyModel, self).__init__(parent)
        self.__showAllChildren = False

    def showAllChildren(self):
        return self.__showAllChildren;

    def setShowAllChildren(self, showAllChildren):
        if showAllChildren == self.__showAllChildren:
            return
        self.__showAllChildren = showAllChildren
        self.invalidateFilter()

    def filterAcceptsRow (self, source_row, source_parent ):
        if self.filterRegExp() == "" :
            return True #Shortcut for common case

        if  super(KSortFilterProxyModel, self).filterAcceptsRow( source_row, source_parent) :
            return True

        #one of our children might be accepted, so accept this row if one of our children are accepted.
        source_index = self.sourceModel().index(source_row, 0, source_parent)
        for i in range( self.sourceModel().rowCount(source_index)):
            if self.filterAcceptsRow(i, source_index):
                return True

        return False

However this aproach doesn’t seems to be efficient because with 300 items it takes almost 3 seconds to update the view, i want to know if theres a better way of doing it.

PD: This class is basically a translation of a KSysGuard one i found in KDE websvn

  • 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-16T12:33:21+00:00Added an answer on May 16, 2026 at 12:33 pm

    I don’t see anything obviously wrong with what you’re doing. Keep in mind that filterAcceptsRow is called for every item in your model, and this is of course going to be sluggish because the overhead of calling a Python function from C++ is a few milliseconds. This adds up rather quickly if you have a model with a few hundred items. Add to this the amount of C++ functions called from Python, and you can easily end up with the 3 seconds you’re noticing.

    Also, QTableView and QSortFilterProxyModel do an awful lot of clever things to keep the signals they emit and the amount of updates required to a minimum. Sadly, this leads to very bad performance if the rows that are removed or added after a filter reset are very much scattered over your model.

    In our projects, we have made the decision to implement most of these item-based models in C++, at least for those methods that are called for every item in a model that contains more than a trivial amount of rows or columns. However, this may not be the answer you’re looking for, especially if your update delays are caused by e.g. other signal handlers connected to the same model. Emitting a signal is usually the same as calling a method.

    In short, you’d best use a profiler to see where your application is spending most of its time, and use C++ if it is in these methods that are called once (or even more than once) per item in your model.

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

Sidebar

Related Questions

I have a custom control: it's managed code, which subclasses System.Windows.Forms.Control. I want to
I want to reimplement a library of which I have the header file. I
have written this little class, which generates a UUID every time an object of
Have a procedure which looks like Procedure TestProc(TVar1, TVar2 : variant); Begin TVar1 :=
Have deployed numerous report parts which reference the same view however one of them
I have a QTreeView which is populated through a reimplementation of QFileSystemModel. As far
I'm using a spinbox with a custom font which looks too high in the
Suppose you have a base class A, and this class is reimplemented by B
I have a working tree model derived from QAbstractItemModel and I wish to filter
I'm using drag and drop on QWidget, I have reimplemented dragEnterEvent, dragLeaveEvent, dragMoveEvent and

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.