Hi all, this bug surfaced after porting KPhotoAlbum to Qt 6. We use a persistent "Copy/Link to" object that helps copying or linking images to the same target directory, keeping the last one as a preset. However, it happened that not all images e.g. copied to some directory actually ended in there. A closer inspection showed that the "native" (i.e. KDE) file dialog does not return the preset directory if one simply presses enter, without clicking on some directory. Instead, the home directory is returned in this case, although the preset directory is shown and selected in the dialog. Using Qt's native file dialogs works as expected. I'll attach a minimal example …
Created attachment 181918 [details] CMakeLists.txt
Created attachment 181919 [details] main.cpp
Created attachment 181920 [details] MainWindow.cpp
Created attachment 181921 [details] MainWindow.h
Steps to see the issue: Compile and ruin the demo obviously ;-) Then: - Click "Get dir (native)" - Choose any directory ("/home/tobias/tmp/9" in my case) - Click "Get dir (native)" again - Press Enter Check the console output: Native file chooser triggered m_lastNative is "" "/home/tobias/tmp/9" m_lastNative is now "/home/tobias/tmp/9" Native file chooser triggered m_lastNative is "/home/tobias/tmp/9" "/home/tobias" m_lastNative is now "/home/tobias" First time, "/home/tobias/tmp/9" is returned, as expected. Second time, "/home/tobias/tmp/9" is pre-selected – but the returned directory is "/home/tobias". Interestingly, this does not happen if you click "OK" using the mouse instead of pressing Enter. In this case, the correct directory is returned. The second button is to compare with Qt's file dialogs. There, it doesn't matter if you click "Select" or press Enter. Which is the expected behavior.
Can reproduce.
The problem here is that pressing the Enter key quickly selects $HOME and then accept the dialog. This doesn't happen if you first manually focus the tree view before pressing Enter, or if you press the OK button instead. Smells like focus handling shenanigans.
Oh! It's because the places panel invisibly has focus by default. So pressing Enter accepts the combobox with the first item in the places panel — which is generally $HOME.
A possibly relevant merge request was started @ https://invent.kde.org/plasma/plasma-integration/-/merge_requests/176
Hey, thanks a lot for tracking this down and for the immediate fix :-) I wanted to check if I could find it myself, but I wasn't sure where to to find the respective code … however, you were faster ;-)
Git commit 5fe925f940be709ac2abde5a8b6f7c77296a6bd4 by Nate Graham. Committed on 06/06/2025 at 21:30. Pushed by ngraham into branch 'master'. kdirselectdialog: correct initial focus It begins with focus on the top-left-most widget, which normally is good. However here that means the Places panel, which is not what you want; you can't start navigating the tree view immediately, and if you pres the Enter key, the top-most Places item gets returned instead of the item visibly selected in the tree view. Instead, start with focus on the main view, which corrects both issues. FIXED-IN: 6.3.6 M +2 -0 qt5/src/platformtheme/kdirselectdialog.cpp M +2 -0 qt6/src/platformtheme/kdirselectdialog.cpp https://invent.kde.org/plasma/plasma-integration/-/commit/5fe925f940be709ac2abde5a8b6f7c77296a6bd4
Git commit 46625af3be99ca43591745054d6d016983cd6800 by Nate Graham. Committed on 09/06/2025 at 14:38. Pushed by ngraham into branch 'Plasma/6.4'. kdirselectdialog: correct initial focus It begins with focus on the top-left-most widget, which normally is good. However here that means the Places panel, which is not what you want; you can't start navigating the tree view immediately, and if you pres the Enter key, the top-most Places item gets returned instead of the item visibly selected in the tree view. Instead, start with focus on the main view, which corrects both issues. FIXED-IN: 6.3.6 (cherry picked from commit 5fe925f940be709ac2abde5a8b6f7c77296a6bd4) Co-authored-by: Nate Graham <nate@kde.org> M +2 -0 qt5/src/platformtheme/kdirselectdialog.cpp M +2 -0 qt6/src/platformtheme/kdirselectdialog.cpp https://invent.kde.org/plasma/plasma-integration/-/commit/46625af3be99ca43591745054d6d016983cd6800
Git commit 29b7cbc42101bac4bcbc96b1c3201ad442a11650 by Nate Graham. Committed on 09/06/2025 at 14:39. Pushed by ngraham into branch 'Plasma/6.3'. kdirselectdialog: correct initial focus It begins with focus on the top-left-most widget, which normally is good. However here that means the Places panel, which is not what you want; you can't start navigating the tree view immediately, and if you pres the Enter key, the top-most Places item gets returned instead of the item visibly selected in the tree view. Instead, start with focus on the main view, which corrects both issues. FIXED-IN: 6.3.6 (cherry picked from commit 5fe925f940be709ac2abde5a8b6f7c77296a6bd4) Co-authored-by: Nate Graham <nate@kde.org> M +2 -0 qt5/src/platformtheme/kdirselectdialog.cpp M +2 -0 qt6/src/platformtheme/kdirselectdialog.cpp https://invent.kde.org/plasma/plasma-integration/-/commit/29b7cbc42101bac4bcbc96b1c3201ad442a11650