diff options
-rw-r--r-- | src/quicktemplates2/qquicksplitview.cpp | 12 | ||||
-rw-r--r-- | tests/auto/controls/data/tst_splitview.qml | 16 |
2 files changed, 24 insertions, 4 deletions
diff --git a/src/quicktemplates2/qquicksplitview.cpp b/src/quicktemplates2/qquicksplitview.cpp index 75cd9674..108dbe07 100644 --- a/src/quicktemplates2/qquicksplitview.cpp +++ b/src/quicktemplates2/qquicksplitview.cpp @@ -849,6 +849,8 @@ QQuickSplitViewPrivate::EffectiveSizeData QQuickSplitViewPrivate::effectiveSizeD int QQuickSplitViewPrivate::handleIndexForSplitIndex(int splitIndex) const { + // If it's the first and only item in the view, it doesn't have a handle, + // so return -1: splitIndex (0) - 1. // If it's the last item in the view, it doesn't have a handle, so use // the handle for the previous item. return splitIndex == contentModel->count() - 1 ? splitIndex - 1 : splitIndex; @@ -1016,11 +1018,13 @@ void QQuickSplitViewPrivate::itemVisibilityChanged(QQuickItem *item) // of the corresponding handle (if one exists). const int handleIndex = handleIndexForSplitIndex(itemIndex); - QQuickItem *handleItem = m_handleItems.at(handleIndex); - handleItem->setVisible(item->isVisible()); + if (handleIndex != -1) { + QQuickItem *handleItem = m_handleItems.at(handleIndex); + handleItem->setVisible(item->isVisible()); - qCDebug(qlcQQuickSplitView) << "set visible property of handle item" - << handleItem << "at index" << handleIndex << "to" << item->isVisible(); + qCDebug(qlcQQuickSplitView) << "set visible property of handle item" + << handleItem << "at index" << handleIndex << "to" << item->isVisible(); + } updateHandleVisibilities(); updateFillIndex(); diff --git a/tests/auto/controls/data/tst_splitview.qml b/tests/auto/controls/data/tst_splitview.qml index a03c09a0..bd36e898 100644 --- a/tests/auto/controls/data/tst_splitview.qml +++ b/tests/auto/controls/data/tst_splitview.qml @@ -1958,4 +1958,20 @@ TestCase { mouseRelease(targetHandle, -100, targetHandle.height / 2, Qt.LeftButton) verify(!control.resizing) } + + Component { + id: oneItemComponent + + SplitView { + Item {} + } + } + + // QTBUG-79270 + function test_hideSplitViewWithOneItem() { + var control = createTemporaryObject(oneItemComponent, testCase) + verify(control) + // Shouldn't be an assertion failure. + control.visible = false + } } |