Reputation: 1856
I have two custom delegates that implement the sizeHint member function like this:
QSize MovieListPosterDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &) const
{
return {option.rect.width(), 80};
}
QSize MovieListTextDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &) const
{
return {option.rect.width(), 40};
}
If I set the text delegate first, the row height is 40px. If I set the poster delegate first, the row height is 80px. But if, after setting one, I try to change it to another, the row height won't change, e.g.:
First let's set the poster delegate, everything works:
Let's then change it to the text delegate:
As you can see there's 40px of extra space that won't go away. And if I try to do it the other way (from text to poster delegate) then it's a mess. I need the view to adjust the row height correctly. How? Thanks.
Upvotes: 0
Views: 961
Reputation: 2210
Use the QAbstractItemView::reset()
method to reset the internal state of the view after changing delegate.
Upvotes: 1