QAbstractItemDelegate and sizeHint issue
Hi,
in a more complicated case I need to determinate the hight of a text block in sizeHint(). Therefore I test it on the following code.
Code:
{
public:
{}
{
const QString text
= index.
data(Qt
::DisplayRole).
toString();
QRect r
= option.
rect.
adjusted(2,
2,
-2,
-2);
painter->drawText(r.left(), r.top(), r.width(), r.height(), Qt::AlignVCenter|Qt::AlignLeft|Qt::TextWordWrap, text, &r);
}
{
const QString text
= index.
data(Qt
::DisplayRole).
toString();
QRect r
= option.
rect.
adjusted(2,
2,
-2,
-2);
QSize s
= option.
fontMetrics.
boundingRect(r.
left(), r.
top(), r.
width(), r.
height(), Qt
::AlignVCenter|Qt
::AlignLeft|Qt
::TextWordWrap, text
).
size();
return s;
}
};
The problem for me is, that "option.rect" doesn't represent the same QRect in the two functions. How is it possible to determinate the hight of the drawn text in sizeHint().
Thanks,
Lykurg