PDA

View Full Version : Word wrapping in a QTableWidget cell



jcooperddtd
28th April 2007, 02:37
I can't seem to find any way to get a QTableWidget cell to word wrap its text, particularly if it is rich text (or text with simple HTML tags).

QTableWidgetItem doesn't provide any means to enable or set word wrapping parameters. Moreover, a QTableWidgetItem doesn't appear to support rich text or HTML.

If I try to employ a QLabel as a cell widget, I get rich text and word wrapping, but for some reason I lose normal table cell selection behavior. Clicking on such a cell produces no visual "selection" indication like a regular QTableWidgetItem does, while double-clicking on it turns the cell blue and leaves the text black.

What I am trying to do is build a single-column table in which each cell displays a piece of rich text (or simple HTML). I want the text in each cell to wrap to the width of the table and the height of each cell to grow to whatever height is necessary to display the entire wrapped text in that cell. Oh, and I want normal cell selection behaviors to be maintained.

jpn
29th April 2007, 21:48
See this thread (http://www.qtcentre.org/forum/f-qt-programming-2/t-qstandarditem-subpart-of-the-text-as-bold-5548.html).

jcooperddtd
30th April 2007, 18:44
Thanks for the tip!

I wrote a QAbstractItemDelegate subclass which implements paint() and sizeHint(), but while the paint() function is being called nicely, it doesn't look like the sizeHint() function is being called. I am using my subclass as a QTableWidget's item delegate, and without my sizeHint() being called, the table's cells are never sized to the correct height.

Do I need to do anything special to get my subclass's sizeHint() function to be called from the QTableWidget?

jcooperddtd
1st May 2007, 03:57
I found it.

QTableView::resizeRowsToContents()