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