[Interest] QSortFilterProxyModel::removeRows()

Paul England pengland at cmt-asia.com
Fri Jun 1 07:15:29 CEST 2012


I wrote this really long email, and learned a lot about the problem in
doing so.  So, I guess it was time well spent.  Still frustrated. 
Here's the summed up problem:

I have a QAbstrctTabelModel, QSortFilterProxyModel, QItemDelegate, and a
QTableView (all subclassed).  As you'd expect, the QSortFilterProxyModel
filters out what I don't want, the delegate paints what I do, and the
view displays everything.  Some rows are updated, and based on
user-defined criteria, need to be removed *AFTER* the proxy  has let
them in.  Before, I was calling invalidate() in the proxy, but that was
calling filterAcceptsRow() on all rows (visible or not).  Yikes.  So,
I'm now doing removeRows() for the row(s) that must be removed.

Caveat: my subclassed delegate's paint() is being passed a QModelIndex()
with the *old* data.

Example, my rows are.

bool my_proxy::removeRows( int row, int count, const QModelIndex& )

    beginRemoveRows( QModelIndex(), row, count + row - 1 );
    // remove data from model here


if I do:
removeRows( 2, 1 );

My model will then show it only has two items.
Harry and Bob

HOWEVER, for the subsequent call to my_delegeate::paint( QPainter*,
const QStyledOptionViewItem& opt, const QModelIndex& index ) will have
the old index.  paint will be called twice, and index.data().toString()
will have Harry for the 1st one, and Larry for the 2nd. 

Am I missing something?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120601/4ed52f24/attachment.html>

More information about the Interest mailing list