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. Expand cell of QTableWidget when click on it

Expand cell of QTableWidget when click on it

Scheduled Pinned Locked Moved Unsolved General and Desktop
2 Posts 2 Posters 686 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.
  • E Offline
    E Offline
    EmmanuelC
    wrote on last edited by
    #1

    Hello,

    I am using a QTableWidget to display some data, with the option horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch), so that the columns fit the width of my widget. Also the cells are not editable.

    The problem I have here is that with the stretch option, the columns are not resizable, and if the text is too long on a cell, we can't see it entirely. So what I would like to do is to expand the cell to fit the entire text, when the user click on it. It is already done when the cell is in mode "editable". Like in the following picture : cellNotExpanded.PNG
    cellExpanded.png

    Is there a simple way to do the same, even when the mode is not editable?

    Thank you and regards,

    Emmanuel

    JonBJ 1 Reply Last reply
    0
    • E EmmanuelC

      Hello,

      I am using a QTableWidget to display some data, with the option horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch), so that the columns fit the width of my widget. Also the cells are not editable.

      The problem I have here is that with the stretch option, the columns are not resizable, and if the text is too long on a cell, we can't see it entirely. So what I would like to do is to expand the cell to fit the entire text, when the user click on it. It is already done when the cell is in mode "editable". Like in the following picture : cellNotExpanded.PNG
      cellExpanded.png

      Is there a simple way to do the same, even when the mode is not editable?

      Thank you and regards,

      Emmanuel

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @EmmanuelC
      The simplest would be to look at https://doc.qt.io/qt-5/qtableview.html#resizeColumnToContents. This would resize the whole column for the longest visible content, you'd have to decide whether that is acceptable. I don't know of an in-built "resize column for content of only one cell", you would have to go via https://doc.qt.io/qt-5/qtableview.html#sizeHintForColumn and measure the text width for that.

      In the edit case the current editable text is allowed to spill/span across columns, and without affecting the column width. This isn't going to work when displaying the whole column.

      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