diff options
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 8 | ||||
-rw-r--r-- | tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp | 12 |
2 files changed, 16 insertions, 4 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index c5601b63b2..3bb4d0624f 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -3020,8 +3020,8 @@ int QAbstractItemView::sizeHintForRow(int row) const const QModelIndex index = d->model->index(row, c, d->root); if (QWidget *editor = d->editorForIndex(index).widget.data()) height = qMax(height, editor->height()); - int hint = d->delegateForIndex(index)->sizeHint(option, index).height(); - height = qMax(height, hint); + if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index)) + height = qMax(height, delegate->sizeHint(option, index).height()); } return height; } @@ -3050,8 +3050,8 @@ int QAbstractItemView::sizeHintForColumn(int column) const const QModelIndex index = d->model->index(r, column, d->root); if (QWidget *editor = d->editorForIndex(index).widget.data()) width = qMax(width, editor->sizeHint().width()); - int hint = d->delegateForIndex(index)->sizeHint(option, index).width(); - width = qMax(width, hint); + if (const QAbstractItemDelegate *delegate = d->delegateForIndex(index)) + width = qMax(width, delegate->sizeHint(option, index).width()); } return width; } diff --git a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp index 7e73c19539..55fcf04846 100644 --- a/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp +++ b/tests/auto/widgets/itemviews/qheaderview/tst_qheaderview.cpp @@ -239,6 +239,8 @@ private slots: void testStreamWithHide(); void testStylePosition(); + void sizeHintCrash(); + protected: void setupTestData(bool use_reset_model = false); void additionalInit(); @@ -2879,5 +2881,15 @@ void tst_QHeaderView::testStylePosition() QCOMPARE(proxy.lastPosition, QStyleOptionHeader::OnlyOneSection); } +void tst_QHeaderView::sizeHintCrash() +{ + QTreeView treeView; + QStandardItemModel *model = new QStandardItemModel(&treeView); + model->appendRow(new QStandardItem("QTBUG-48543")); + treeView.setModel(model); + treeView.header()->sizeHintForColumn(0); + treeView.header()->sizeHintForRow(0); +} + QTEST_MAIN(tst_QHeaderView) #include "tst_qheaderview.moc" |