Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to optimize PyQt QSortFilterProxyModel filter reimplementation?
    text
    copied!<p>I have a reimplemented QSortFilterProxyModel acceptRows to achieve custom behavior, i want it to not filter out items which have a valid child.</p> <pre><code>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 </code></pre> <p>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.</p> <p>PD: This class is basically a translation of a KSysGuard one i found in <a href="http://websvn.kde.org/trunk/KDE/kdebase/workspace/ksysguard/gui/ksortfilterproxymodel.h?view=log" rel="nofollow noreferrer">KDE websvn</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload