Ok, I have worked out a work-around, not the prettiest solution but it works...
Basically, the code uses the QTextLayout to calculate the (natural) lengths of each line and adds them up and does this for n-1 lines. For the last line it simply adds the full width available and then creates an elided string with all the widths as if they were intended to be on one long line. Then the painter simply draw the text with word wrapping.
@
QTextLayout textLayout(text);
textLayout.setFont(font);
int widthUsed = 0;
int lineCount = 0;
textLayout.beginLayout();
while (++lineCount < LINE_LIMIT) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(availableWidth);
widthUsed += line.naturalTextWidth();
}
textLayout.endLayout();
widthUsed += availableWidth;
QString newText = painter->fontMetrics().elidedText(text, Qt::ElideRight, widthUsed);
painter->drawText(textRect, Qt::AlignLeft | Qt::AlignTop | Qt::TextWordWrap, newText);
@