简体   繁体   中英

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. 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. Qt didn't go to the lengths needed to wrap actions around the native dialog. 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.

The action would presumably work if you were to switch to a non-native file dialog.

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