Resize TableView column based on contents in a column
-
Hi,
How about using "resizeColumnsToContents":http://qt-project.org/doc/qt-5/qml-qtquick-controls-tableview.html#resizeColumnsToContents-method ?
-
Sorry but I’m not understanding. Do you mean you want to explicitly set the width ? and it should be based upon the contents ? Can you elaborate ?
-
AFAIK there's no such property to set. But you could easily do it by iterating over the contents of TableView's particular column of interest and then storing the length of the text as per your condition. This can then be used to set the width of that particular column.
@
tableview.getColumn(indexofcolumn).width = length-of-text*some-multiplication-factor
@ -
Using JavaScript String length Property.
-
ruysch: It is probably a bad idea to do this though. TableView doesn't know the width of items that are not visible on screen. This is because a model could have millions of data entries, and would have to actually fetch and instantiate every single one of them in order to calculate the minimum width. Obviously this will not scale well, so resizeToContents will only give you the with of items currently in view. Perhaps you could rather solve this by creating a tool tip or open an extended view if the data doesn't fit on the current column width.
-
ruysch: I believe that is a known issue. I think this would be the appropriate task for it: https://bugreports.qt-project.org/browse/QTBUG-36518