Unsolved QFileDialog delete multiple files at once
-
This post is deleted! -
Although the answer is probably "no" in any case, are you using the native dialog or the Qt one, as they doubtless work differently? And if it's the native one, the behaviour doubtless depends on the platform too.
-
@JonB I am using the Qt one. Does that mean I have to re-implement FileDialog myself to get the implementation that I need?
-
@mcarter
TBH I don't know what it offers. If it does not offer what you want, then you have some reimplementation to do. You can derive fromQFileDialog
if needed. See also http://www.qtcentre.org/threads/69138-Adding-my-own-file-deletion-method-to-QFileDialog-getSaveFileName (someone else wanting to do something vaguely similar). -
@JonB lol, I saw that same thread, but noone has answered
ugh, it seems reimplementation is a standard protocol when working with Qt, but hiding everything in a private class makes it so difficult.
thanks for the info
-
@mcarter said in QFileDialog delete multiple files at once:
but hiding everything in a private class makes it so difficult.
Yeah, its the price of binary compatibility. sadly.
Why not just use QFileDialog ability to select multiple files
and simply loop over selection list and manually delete the files?
That way you can ignore any that didn't get deleted and process rest of list ? -
@mrjj said in QFileDialog delete multiple files at once:
@mcarter said in QFileDialog delete multiple files at once:
but hiding everything in a private class makes it so difficult.
Yeah, its the price of binary compatibility. sadly.
not really, there could be methods to allow access to the inner workings and a lot more virtual methods, like 'virtual void deleteCurrent();' to get access to the delete process.
Why not just use QFileDialog ability to select multiple files
and simply loop over selection list and manually delete the files?
That way you can ignore any that didn't get deleted and process rest of list ?but once the user chooses 'Delete' from the right-click menu, I do not have access to anything, becomes all internal. So I do not see how deriving from QFileDialog will help with anything unless I can replace the Delete action slot with my own implementation. Would that be possible?
-
@mcarter Why would a user want to delete files inside QFileDialog? To me this sounds like a wrong use case. For deleting you usually provide a button/menu/... which opens a dialog where user selects files to delete and clicks "OK".
-
@jsulm
While I do not disagree with your sentiment, to be fair (so far as I know, for both Windows & Linux [Ubuntu Unity Desktop]), the native file dialog does allow user to delete files as well as load/save. For example, many games which allow user to load from a previous save also allow user to delete those saves from same dialog while looking at what saves exist. Though I have never tried to delete multiple files from there.I set things up to allow selecting multiple ExistingFiles.
The way you write this implies to me that you are (perhaps) only allowing multiple-file-selection-for-load in order to allow multiple delete. If that is the case, you should not be allowing multiple multiple loads just to allow multiple deletes --- your load dialog should offer single/multiple only according as your program allows single/multiple loads.
-
@jsulm
Having a QFileDialog just for deleting may be my final recourse, but the current Qt-based QFileDialog still has Delete as an option from the right-click menu and I do not think I can change that . . . so would still like that to work if it is an option for the user.@JonB
The user wants the ability to load in multiple files so that is why the ExistingFiles on load; the multiple delete was just a nice byproduct, that I hoped worked out of the box. Is there really no way to get access to the delete process without a reimplementation of the widget? -
@mcarter said in QFileDialog delete multiple files at once:
the current Qt-based QFileDialog still has Delete as an option from the right-click menu and I do not think I can change that
You can disable the 'delete' option though by setting the
QFileDialog::ReadOnly
option flag:QFileDialog dialog(this); dialog.setFileMode(QFileDialog::ExistingFiles); dialog.setOptions(QFileDialog::ReadOnly | QFileDialog::DontUseNativeDialog); dialog.exec();
So what remains to be done in order to provide the multiple-file selection
Delete
option is to provide a 3rd QFileDialog invokation to explicitly delete files then. This could be done by just using the open file dialog, and renaming the dialog's title andAccept
button as follows:QFileDialog dialog(this, tr("Delete File(s)")); dialog.setFileMode(QFileDialog::ExistingFiles); dialog.setOptions(QFileDialog::ReadOnly | QFileDialog::DontUseNativeDialog); dialog.setAcceptMode(QFileDialog::AcceptOpen); dialog.setLabelText(QFileDialog::Accept, tr("Delete")); if (dialog.exec()) { qDebug() << dialog.selectedFiles(); //Delete all the files in the selection here .... }
So now, Qt's implementation of the
Delete
operation is disabled since it can no longer be accessed via the context menu (although maybe the keyboard shortcuts could still work?) and you can implement your own code to delete the files without the nagging confirmation dialogs.