PDA

View Full Version : Different size hint for selected cells in QListItemView



andras
23rd October 2009, 15:47
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:


QSize MyDelegate::sizeHint(const QStyleOptionViewItem& option, const QModelIndex& index) const
{
const bool sel(option.state.testFlag(QStyle::State_Selected)) ;

QSize size1;
QSize size2;

/* 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

wysota
25th October 2009, 10:01
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.

andras
27th October 2009, 23:02
Hi, wysota, thanks for making that clear. For now, I think I'll stick with uniform size -- the other solution seems a little complicated...