pisoengracia at gmail.com
Fri Jun 1 08:01:10 CEST 2012
El dv 01 de 06 de 2012 a les 14:15 +0900, en/na Paul England va
> 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?
Perhaps the fact that indexes are 0-based ?
0 - Harry
1 - Larry
2 - Bob
So if you call removeRows( 2, 1 ); you're removing Bob, as expected...
More information about the Interest