Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-9352

QTableView::resizeColumnToContents(int) and QTableView::resizeColumnsToContents() do not work as documented




      The QTableView's methods resizeColumnToContents(int) and resizeColumnsToContents() do not work as documented!

      This issue has already been reported in 2005: http://lists.trolltech.com/qt-interest/2005-09/thread01227-0.html

      I would like to resize a column of a QTableWidget to the longest text of an QTableWidgetItem in that column.
      I thought that would do the function resizeColumnToContents(..), but somehow it does not detect the longest text.
      Its only working with the rows that are visible, for me.
      The columns for the rows outside the view are not resized!

      Unfortunately, it was not taken serious at that time. So this issue survived many versions of Qt, confusing a lot of developers.

      When resizeColumnToContents(int) looks for the longest entry in a row, only the visible rows are considered. So only when you scroll down to your longest row, the resizeColumnToContents(int) method will work as expected. Otherwise, it will just resize to the column according to the longest currently visible row.

      Athough this behaviour improves performance for very long tables, it should be possible to disable it via an additional argument, e.g.

      resizeColumnsToContents(bool considerAllRows=false)

      resizeColumnToContents(int row, bool considerAllRows=false)

      In case this isn't possible for some reason, the current behaviour of resizeColumnToContents(int) should be documented at the very least! The documentation just says "Only visible columns will be resized", but that's another story which has nothing to do with the issue described here.

      It should be checked whether a similar issue exists for the dual methods resizeRowToContents(int) and resizeRowsToContents().


        No reviews matched the request. Check your Options in the drop-down menu of this sections header.



            Unassigned Unassigned
            vog Volker Grabsch
            10 Vote for this issue
            8 Start watching this issue



              Gerrit Reviews

                There are no open Gerrit changes