简体   繁体   English

QFileDialog-文件删除通知

[英]QFileDialog - File deletion notification

I am trying to modify the stock QFileDialog to better support the SNFS file-system. 我正在尝试修改库存QFileDialog以更好地支持SNFS文件系统。 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 为DEL键安装一个eventFilter

The event seems to get stopped by QFileDialog before it gets to my filter. 该事件似乎在进入我的过滤器之前被QFileDialog停止了。

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. 文件对话框有两种:本机对话框和Qt对话框。 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. 本机对话框跟踪Windows和OS X上的文件系统状态,可能会因平台特定而稍有延迟,并以相同的程度出现在所有应用程序中。 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. Qt对话框(始终在Windows上以及可选地在其他平台上使用)使用文件系统模型,该文件系统模型将在可能的情况下通知文件系统状态更改。

Questions that have to be answered: 必须回答的问题:

  1. Which dialog are you using (native or Qt)? 您正在使用哪个对话框(本机或Qt)? The DontUseNativeDialog option can be set to force a Qt dialog. 可以将DontUseNativeDialog选项设置为强制执行Qt对话框。

  2. Does SNFS on your platform implement filesystem change notifications? 您平台上的SNFS是否实现文件系统更改通知?

  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. 您是否验证了文件系统更改通知是否正常工作并被Qt的QFileSystemModel -如果是这样,无论平台对话框是否存在,Qt文件对话框都会收到通知。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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