Determining correct row height for multi-line QTableWidgetItem?
-
I've got a table cell that is displaying multi-line text that wraps and can have newlines, displaying any number of lines as needed based on the table's width.
Up to now I've been using my own code to determine the ideal height for a row, because I have found that it is much more accurate than resizeRowToContents, which seems to be off by a factor of 4.
My code is based on QFontMetrics's boundingRect. However my code is not as accurate as I want, either. There seem to be internal margins to the QTableWidgetItem that I'm not yet taking into account.
So, what is the best way to determine the ideal height for a row that has multiple lines?
Why is resizeRowsToContents so inaccurate?Thanks.
-
I see there's been no response. Is this a part of Qt that is just known to be buggy? Maybe no one wants to address the bug?
-
Perhaps there is no response because there is nothing in your original post to let people to demonstrate the claimed problem or what you have actually done.
You make assertions that resizeRowToContents computed row height is off by a factor of four: bigger or smaller is unknown, but this seems very unlikely to have gone unnoticed. Then you tell us your own code is fails to meet your expectations in some unspecified way. We see neither the problem nor your code so it is very difficult to help you.
Try posting a small, self-contained example that demonstrates the problem with screen shots, then you might have a better response.
-
@VRonin
This is how I programmatically determine the row height.int presumed_internal_padding = 12; int widgetWidth = table->width() - 2 * presumed_internal_padding; QFont font("Helvetica", fontsize, false, false); QFontMetrics metrics(font); QRect rect = metrics.boundingRect(0, 0, widgetWidth, INT_MAX, Qt::TextWordWrap, theText, 0, NULL); return rect.height();