Important: Please read the Qt Code of Conduct -

QTableWidget - Word Wrap

  • What does exactly setWordWrap(bool) do on QTableWidget? I would like to display text in a table at index(line,column) that wraps when resizing the window that depends on the space (width) available in a column. Thanks for your comments/answers.

  • from "":
    If this property is true then the item text is wrapped where necessary at word-breaks; otherwise it is not wrapped at all. This property is true by default.
    Note that even of wrapping is enabled, the cell will not be expanded to fit all text. Ellipsis will be inserted according to the current textElideMode.

  • You can use QTableView::resizeRowToContents(row) or ::resizeRowsToContents() to make the text fit the cells in your table.

  • I would like to have the text wrapped to the next item line (having the table line height increased) instead of displaying "..." when the window size is too small. I will try the QTableView::resizeRowToContents(row) option.

  • It seems that the resizeRowToContents(row) does work (somewhat).

    However when I create the row like this :

    TableWidgetItem *descriptionItem = new QTableWidgetItem("String");
    setItem (row, column,descriptionItem);

    It has no effet on the row.

    I have to manually call resizeRowToContents(index) with a timer to make it work.

    Any thoughts?

    Edit: Use tag @ for code

  • In this case row=index...

  • doumdi did you ever figure this out? I am having a similar problem, the rows will resize some but not enough to show the text on a second line

  • try it to adjust one of the columns to adapt to the size of QTableWdiget :

    int col =2; // chose the column 2 for adjust;
    QTableWdiget *tw = new QTableWdiget(this);

  • Thanks francomartins, I figured out about resizing the rows in another post but what you suggested will also be helpful with some of my other columns.

  • Although this is an old thread I think I came up with a very simple solution:
    SIGNAL(sectionResized(int, int, int)),
    This will adjust the word wrapping automatically every time a column resizes.

Log in to reply