简体   繁体   中英

QFileDialog - File deletion notification

I am trying to modify the stock QFileDialog to better support the SNFS file-system. Currently it doesn't update after deleting files. So if a user deletes a file, the file is still shown in the Dialog.

So what I need is some way to get notified once the user has deleted a file from the dialog, or a way to remove the default shortcut so I can implement my own.

What I've tried so far:

Installing an eventFilter for the DEL key

The event seems to get stopped by QFileDialog before it gets to my filter.

Adding my own Shortcut

This results in :

QAction::eventFilter: Ambiguous shortcut overload: Del

Removing set Shortcuts

I call the following function on the dialog to recursively remove all set shortcuts and actions:

def to_children(self, parent):
    for child in parent.children():
        if hasattr(child, 'removeAction'):
            for a in child.actions():
                child.removeAction(a)
        if hasattr(child, 'releaseShortcut'):
            for i in range(100):
                self.releaseShortcut(i)
        self.to_children(child)

However the shortcut still works.

There are many ways of deleting files - hooking shortcuts won't help you.

There are two kinds of file dialogs: native and Qt dialogs. Native dialogs track filesystem state on both Windows and OS X, perhaps with a slight delay that is platform specific and present in all applications in to the same degree. On these platforms, you shouldn't need to do anything further. Qt dialogs, always used on Windows, and optionally on other platforms, use a filesystem model that will, when it can, get notified of filesystem state changes.

Questions that have to be answered:

  1. Which dialog are you using (native or Qt)? The DontUseNativeDialog option can be set to force a Qt dialog.

  2. Does SNFS on your platform implement filesystem change notifications?

  3. Did you verify that the filesystem change notifications work and are picked up by Qt's QFileSystemModel - if so, Qt file dialogs will be notified whether the platform dialogs are or not.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM