简体   繁体   English

Qt 5.7 QFileDialog操作不起作用

[英]Qt 5.7 QFileDialog action doesn't work

I got filedialog called inside my main window with this code: 我在主窗口中使用以下代码调用了文件对话框:

QAction *actionWithShortcut = new QAction();
actionWithShortcut->setShortcut(Qt::CTRL + Qt::Key_9);
actionWithShortcut->setShortcutContext(Qt::ShortcutContext::WidgetWithChildrenShortcut);
// added this comment to check does it work at list outside filedialog
// addAction(actionWithShortcut);
QFileDialog *fd = new QFileDialog(this);
fd->addAction(actionWithShortcut);
connect(actionWithShortcut, &QAction::triggered, fd, &QFileDialog::reject);
fd->show();

But looks like I can't add any actions to QFileDialog or they are somehow omitted. 但是看起来我无法向QFileDialog添加任何动作,或者它们以某种方式被省略了。 Any suggestions? 有什么建议么? Already tried window flags, options and etc. Can't find any solutions. 已尝试使用窗口标志,选项等。找不到任何解决方案。

By default, a QFileDialog is a thin wrapper around the native dialog. 默认情况下, QFileDialog是本机对话框的薄包装。 Qt didn't go to the lengths needed to wrap actions around the native dialog. Qt没有达到将动作包装在本地对话框周围所需的长度。 So this is a case of a missing implementation. 因此,这是缺少实现的情况。 You could patch Qt to make it work on a platform of your choice, and contribute the change back, of course. 您可以修补Qt,使其在您选择的平台上运行,然后退还所做的更改。

The action would presumably work if you were to switch to a non-native file dialog. 如果您要切换到非本地文件对话框,则该操作可能会起作用。

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

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