summaryrefslogtreecommitdiff
path: root/src/controls/TableViewColumn.qml
diff options
context:
space:
mode:
authorShawn Rutledge <shawn.rutledge@digia.com>2013-08-14 12:07:58 +0200
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-01-22 18:29:44 +0100
commit0b575c91d3f2fcd1d22b759ab7c9b6ffe8d4cea0 (patch)
tree9c6062c2af2150913ef06258d2500a31ddca162d /src/controls/TableViewColumn.qml
parentb5e1ed76942c1b0feb7a58db5fe9f24ce33e06f2 (diff)
downloadqtquickcontrols-0b575c91d3f2fcd1d22b759ab7c9b6ffe8d4cea0.tar.gz
TableView: added resizeToContents and resizeColumnsToContents
These are analogous to QTableView::resizeColumnToContents(i) and resizeColumnsToContents(). Double-clicking the header near a width adjustment boundary still provides a means for the user to do this if the application doesn't do it programmatically. Change-Id: Ibded0c9f255301b461dac7080901fc6065fdbe5e Reviewed-by: Caroline Chao <caroline.chao@digia.com> Reviewed-by: Shawn Rutledge <shawn.rutledge@digia.com> Reviewed-by: Jens Bache-Wiig <jens.bache-wiig@digia.com>
Diffstat (limited to 'src/controls/TableViewColumn.qml')
-rw-r--r--src/controls/TableViewColumn.qml21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/controls/TableViewColumn.qml b/src/controls/TableViewColumn.qml
index cbf20945..30551f90 100644
--- a/src/controls/TableViewColumn.qml
+++ b/src/controls/TableViewColumn.qml
@@ -53,6 +53,9 @@ QtObject {
/*! \internal */
property Item __view: null
+ /*! \internal */
+ property int __index: -1
+
/*! The title text of the column. */
property string title
@@ -119,4 +122,22 @@ QtObject {
property Component delegate
Accessible.role: Accessible.ColumnHeader
+
+ /*! Resizes the column so that the implicitWidth of the contents on every row will fit.
+ \since QtQuick.Controls 1.2 */
+ function resizeToContents() {
+ var minWidth = 0
+ var listdata = __view.__listView.children[0]
+ for (var i = 0; __index < 0 && i < __view.__columns.length; ++i)
+ if (__view.__columns[i] === this)
+ __index = i
+ for (var row = 0 ; row < listdata.children.length ; ++row) {
+ var item = listdata.children[row+1]
+ if (item && item.children[1] && item.children[1].children[__index] && item.children[1].children[__index].children[0] &&
+ item.children[1].children[__index].children[0].hasOwnProperty("implicitWidth"))
+ minWidth = Math.max(minWidth, item.children[1].children[__index].children[0].implicitWidth)
+ }
+ if (minWidth)
+ width = minWidth
+ }
}