aboutsummaryrefslogtreecommitdiffstats
path: root/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp
diff options
context:
space:
mode:
authorOliver Eftevaag <oliver.eftevaag@qt.io>2025-07-30 17:53:30 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2025-08-15 23:33:19 +0000
commitd4c38354ee6bcf22ec236ab14dde5297036a94bd (patch)
tree287693b433ff7835e0ff849c398e4e2505f9b922 /src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp
parent63d8a9d1c9c89c60943c066676f8d434344d561c (diff)
FileDialog: Use SplitView to separate the sidebar from the content
Previously a RowLayout was being used. But I would argue that it's better UI to use a SplitView instead. Add the necessary overrides in QQuickSideBar, so that the SideBar actually knows it's correct implicit size. This is needed in order for the SplitView to work correctly. We want the implicit width to be large enough to cover the delegate with the most text, with a maximum width of half the available space in the dialog. As for the height, we want it to be tall enough to cover all the standard paths + add favorite button, so that the feature of adding directories to the favorite list is less cumbersome. The height of the sidebar should be part of what determines the implicit height of the dialog. Change-Id: If267d8197e82f8a91a059e31723c46fe95af3d41 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit 2f95385b89ae145f4c2d37bcda509d9ed817b5a6) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp')
-rw-r--r--src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp b/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp
index 9df7f681df..32488e83e2 100644
--- a/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp
+++ b/src/quickdialogs/quickdialogsquickimpl/qquickfiledialogimpl.cpp
@@ -369,11 +369,15 @@ void QQuickFileDialogImpl::setInitialCurrentFolderAndSelectedFile(const QUrl &fi
d->updateFileNameTextEdit();
d->setCurrentIndexToInitiallySelectedFile = true;
+ bool isListViewCurrentIndexNegative = false;
+ if (const auto *attached = d->attachedOrWarn())
+ isListViewCurrentIndexNegative = attached->fileDialogListView()->currentIndex() < 0;
+
// If the currentFolder didn't change, the FolderListModel won't change and
// neither will the ListView. This means that setFileDialogListViewCurrentIndex
// will never get called and the currentIndex will not reflect selectedFile.
// We need to account for that here.
- if (!currentFolderChanged) {
+ if (!currentFolderChanged || isListViewCurrentIndexNegative) {
const QFileInfo newSelectedFileInfo(d->selectedFile.toLocalFile());
const int indexOfSelectedFileInFileDialogListView = d->cachedFileList.indexOf(newSelectedFileInfo);
d->tryUpdateFileDialogListViewCurrentIndex(indexOfSelectedFileInFileDialogListView);
@@ -744,10 +748,15 @@ void QQuickFileDialogImplAttached::setFileDialogListView(QQuickListView *fileDia
if (fileDialogListView == d->fileDialogListView)
return;
+ if (d->fileDialogListView)
+ QObjectPrivate::disconnect(d->fileDialogListView, &QQuickListView::currentIndexChanged,
+ d, &QQuickFileDialogImplAttachedPrivate::fileDialogListViewCurrentIndexChanged);
+
d->fileDialogListView = fileDialogListView;
- QObjectPrivate::connect(d->fileDialogListView, &QQuickListView::currentIndexChanged,
- d, &QQuickFileDialogImplAttachedPrivate::fileDialogListViewCurrentIndexChanged);
+ if (d->fileDialogListView)
+ QObjectPrivate::connect(d->fileDialogListView, &QQuickListView::currentIndexChanged,
+ d, &QQuickFileDialogImplAttachedPrivate::fileDialogListViewCurrentIndexChanged);
emit fileDialogListViewChanged();
}