diff options
author | Thierry Bastian <thierry.bastian@nokia.com> | 2009-10-27 11:15:49 (GMT) |
---|---|---|
committer | Thierry Bastian <thierry.bastian@nokia.com> | 2009-10-27 11:17:20 (GMT) |
commit | bc49cbaab3356770eb4b27dcbc2e585bf21e9200 (patch) | |
tree | 4e21e292cb4764ec498d6929b9570f4a73fc49fb | |
parent | ca7640ff5e12f9e818d3b8ca38318f0fdcf47e3e (diff) | |
download | Qt-bc49cbaab3356770eb4b27dcbc2e585bf21e9200.zip Qt-bc49cbaab3356770eb4b27dcbc2e585bf21e9200.tar.gz Qt-bc49cbaab3356770eb4b27dcbc2e585bf21e9200.tar.bz2 |
QTableView would not correctly resize to contents
The problem was that we didn't call ensurePolished when getting the
size of the sections.
Task-number: QTBUG-1002
Reviewed-by: ogoffart
-rw-r--r-- | src/gui/itemviews/qheaderview.cpp | 2 | ||||
-rw-r--r-- | src/gui/itemviews/qtableview.cpp | 4 | ||||
-rw-r--r-- | tests/auto/qtableview/tst_qtableview.cpp | 11 |
3 files changed, 12 insertions, 5 deletions
diff --git a/src/gui/itemviews/qheaderview.cpp b/src/gui/itemviews/qheaderview.cpp index fc9820f..4b5ec71 100644 --- a/src/gui/itemviews/qheaderview.cpp +++ b/src/gui/itemviews/qheaderview.cpp @@ -2516,6 +2516,8 @@ QSize QHeaderView::sectionSizeFromContents(int logicalIndex) const Q_D(const QHeaderView); Q_ASSERT(logicalIndex >= 0); + ensurePolished(); + // use SizeHintRole QVariant variant = d->model->headerData(logicalIndex, d->orientation, Qt::SizeHintRole); if (variant.isValid()) diff --git a/src/gui/itemviews/qtableview.cpp b/src/gui/itemviews/qtableview.cpp index 2a937f1..c80faa2 100644 --- a/src/gui/itemviews/qtableview.cpp +++ b/src/gui/itemviews/qtableview.cpp @@ -2065,6 +2065,8 @@ int QTableView::sizeHintForRow(int row) const if (!model()) return -1; + ensurePolished(); + int left = qMax(0, columnAt(0)); int right = columnAt(d->viewport->width()); if (right == -1) // the table don't have enough columns to fill the viewport @@ -2122,6 +2124,8 @@ int QTableView::sizeHintForColumn(int column) const if (!model()) return -1; + ensurePolished(); + int top = qMax(0, rowAt(0)); int bottom = rowAt(d->viewport->height()); if (!isVisible() || bottom == -1) // the table don't have enough rows to fill the viewport diff --git a/tests/auto/qtableview/tst_qtableview.cpp b/tests/auto/qtableview/tst_qtableview.cpp index d8110e1..8f8781d 100644 --- a/tests/auto/qtableview/tst_qtableview.cpp +++ b/tests/auto/qtableview/tst_qtableview.cpp @@ -2017,8 +2017,9 @@ void tst_QTableView::resizeRowsToContents() view.resizeRowsToContents(); QCOMPARE(resizedSpy.count(), model.rowCount()); - for (int r = 0; r < model.rowCount(); ++r) + for (int r = 0; r < model.rowCount(); ++r) { QCOMPARE(view.rowHeight(r), rowHeight); + } } void tst_QTableView::resizeColumnsToContents_data() @@ -3267,12 +3268,12 @@ void tst_QTableView::resizeToContents() //now let's check the row/col sizes for(int i = 0;i<table.columnCount();i++) { - QVERIFY( table.columnWidth(i) == table2.columnWidth(i)); - QVERIFY( table2.columnWidth(i) == table3.columnWidth(i)); + QCOMPARE( table.columnWidth(i), table2.columnWidth(i)); + QCOMPARE( table2.columnWidth(i), table3.columnWidth(i)); } for(int i = 0;i<table.rowCount();i++) { - QVERIFY( table.rowHeight(i) == table2.rowHeight(i)); - QVERIFY( table2.rowHeight(i) == table3.rowHeight(i)); + QCOMPARE( table.rowHeight(i), table2.rowHeight(i)); + QCOMPARE( table2.rowHeight(i), table3.rowHeight(i)); } } |