Different size hint for selected cells in QListItemView
Hello, I am trying to implement an item delegate for a list view which should display additional information for any selected item. In order to display this additional information, I would need to allocate more space on screen to the selected item. For this, I tried to implement sizeHint() of the item delegate in the following way:
Code:
QSize MyDelegate
::sizeHint(const QStyleOptionViewItem
& option,
const QModelIndex
& index
) const {
const bool sel
(option.
state.
testFlag(QStyle::State_Selected));
/* compute size1 and size2... */
if (sel)
{
return size1;
}
else
{
return size2;
}
}
However, flag State_Selected does not seem to be set when the size hint is requested from the delegate. Is it a known fact that this flag is set only after the sizeHint method has been called, or am I doing something wrong?
Thanks,
Andras
Re: Different size hint for selected cells in QListItemView
It's a known fact it is not called for sizeHint(). The thing you want to do can't be easily implemented currently. All you can do is to tell your item it is selected and then signal size hint changed from the delegate so that sizeHint is queried again and returns modified data.
Re: Different size hint for selected cells in QListItemView
Hi, wysota, thanks for making that clear. For now, I think I'll stick with uniform size -- the other solution seems a little complicated...