I subclassed QItemDelegate to create some custom/standard labels in the view and open them persistent. the labels' size changes from time to time, depending on the model's data. i wonder how to return a correct sizeHint so that the view knows what size should be assigned to each item. i did like this, obviously, it is not a good way to calculate the right sizeHint, and it doesn't return right size when the data changes.
QSize LabelDelegate::sizeHint(const QStyleOptionViewItem &option,
const QModelIndex &index)const
{
UnselectedLabel *label = new UnselectedLabel(index.data().toString());
QString str = index.data().toString();
label->adjustSize();
QSize sizeHint = label->size();
return sizeHint;
}
Any help will be appreciated, thank you.
Bookmarks