Results 1 to 4 of 4

Thread: Word wrapping in a QTableWidget cell

  1. #1
    Join Date
    Apr 2007
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question Word wrapping in a QTableWidget cell

    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.

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Word wrapping in a QTableWidget cell

    J-P Nurmi

  3. #3
    Join Date
    Apr 2007
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Word wrapping in a QTableWidget cell

    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?

  4. #4
    Join Date
    Apr 2007
    Posts
    4
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Word wrapping in a QTableWidget cell

    I found it.

    QTableView::resizeRowsToContents()

  5. The following user says thank you to jcooperddtd for this useful post:

    wendelmaques (8th November 2011)

Similar Threads

  1. Center a widget in a cell on a QTableWidget
    By roleroz in forum Qt Programming
    Replies: 16
    Last Post: 5th March 2009, 14:47
  2. Word wrapping
    By bruccutler in forum Qt Programming
    Replies: 4
    Last Post: 26th February 2007, 16:33
  3. Selection of cell with QWidget in QTableWidget
    By Tamara in forum Qt Programming
    Replies: 7
    Last Post: 17th February 2007, 14:11
  4. word wrapping in QTable Cell
    By joseph in forum General Discussion
    Replies: 0
    Last Post: 27th November 2006, 09:30
  5. Replies: 3
    Last Post: 8th September 2006, 18:54

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.