[Interest] Dynamically Resizing the height of a Row in a QTableWidget or QTableView

Mark markg85 at gmail.com
Tue Jun 26 01:19:33 CEST 2012


On Mon, Jun 25, 2012 at 11:52 PM, Eric Clark <eclark at ara.com> wrote:
> Hello Mike,
>
> I am not sure about dynamically resizing the row height, but I have a suggestion that you may or may not find helpful...
>
> Instead of placing the entire portion of text in the table cell, why not use the QFontMetrics::elidedText(...) function to add ellipsis to the left, right or middle of your text and then set the tooltip on the cell to show the entire text when the text is too long?
>
> Hope this helps...
> Eric
>
>> -----Original Message-----
>> From: interest-bounces+eclark=ara.com at qt-project.org [mailto:interest-
>> bounces+eclark=ara.com at qt-project.org] On Behalf Of Michael Jackson
>> Sent: Monday, June 25, 2012 3:35 PM
>> To: Interests Qt
>> Subject: [Interest] Dynamically Resizing the height of a Row in a
>> QTableWidget or QTableView
>>
>> Is it possible to dynamically set the row height based on the amount of text
>> that needs to be displayed? We are trying to display some error messages in
>> a table and some of the messages are very short (just a few words) and
>> some of very long (lots and lots of words). Can this be done with a
>> QTableWidget or should we move to a QTableView and custom model? Does
>> anyone have any example code?
>>
>> Thanks
>> ---
>> Mike Jackson
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

Something i figured out by accident is that QFontMetrics::elidedText
is __extremely__ slow in Qt 4.7 and 4.8. I haven't tested it for Qt 5.
I did made a patch for it a while back that made it about 200x faster.
It was even commited to Qt! Sadly also reverted because it caused a
regression somewhere else. I don;t know if the Qt guy for text
rendering picked it up further and made a proper fix in Qt 5.

In my calculations (on a fast AMD 1100T CPU) it spends about 0.2
seconds (roughly the same for windows and linux) on elidedText for
just 1000 lines each consisting of random data with 250 chars. Just so
you know if you notice a performance impact after using that function
:)



More information about the Interest mailing list