Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget - Word Wrap
QtWS25 Last Chance

QTableWidget - Word Wrap

Scheduled Pinned Locked Moved General and Desktop
10 Posts 6 Posters 18.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    doumdi
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • S Offline
      S Offline
      stukdev
      wrote on last edited by
      #2

      from "http://doc.qt.nokia.com/4.7/qtableview.html#wordWrap-prop":http://doc.qt.nokia.com/4.7/qtableview.html#wordWrap-prop
      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.

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • D Offline
          D Offline
          doumdi
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • D Offline
            D Offline
            doumdi
            wrote on last edited by
            #5

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

            However when I create the row like this :

            @
            TableWidgetItem *descriptionItem = new QTableWidgetItem("String");
            descriptionItem->setFlags(Qt::ItemIsEnabled);
            setItem (row, column,descriptionItem);
            resizeRowToContents(index);
            @

            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

            1 Reply Last reply
            0
            • D Offline
              D Offline
              doumdi
              wrote on last edited by
              #6

              In this case row=index...

              1 Reply Last reply
              0
              • C Offline
                C Offline
                confused
                wrote on last edited by
                #7

                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

                1 Reply Last reply
                0
                • F Offline
                  F Offline
                  francomartins
                  wrote on last edited by
                  #8

                  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);
                  tw->horizontalHeader()->setResizeMode(col,QHeaderView::Stretch);
                  @

                  1 Reply Last reply
                  0
                  • C Offline
                    C Offline
                    confused
                    wrote on last edited by
                    #9

                    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.

                    1 Reply Last reply
                    0
                    • R Offline
                      R Offline
                      robert.wloch
                      wrote on last edited by
                      #10

                      Although this is an old thread I think I came up with a very simple solution:
                      @
                      connect(
                      tableWidget->horizontalHeader(),
                      SIGNAL(sectionResized(int, int, int)),
                      tableWidget,
                      SLOT(resizeRowsToContents()));
                      @
                      This will adjust the word wrapping automatically every time a column resizes.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved