In a modal dialog i set the shortcut to the help button, but this shortcut is not working, the button is not clicked if I press the corresponding shortcut.


  1. DialogWithHelpButton::DialogWithHelpButton(QWidget *parent) :
  2. QDialog(parent), ui(new Ui::DialogWithHelpButton)
  3. {
  4. ui->setupUi(this);
  5. QPushButton *helpButton = ui->buttonBox->button(QDialogButtonBox::Help);
  6. helpButton->setShortcut(QKeySequence::HelpContents);
  7. }

I did some tests, and it seems, that the shortcuts only work if set to an action in the menu of the main application windows. If I open the dialog as non modal, the application shortcut also work, but not if the dialog is open as modal.


  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent), ui(new Ui::MainWindow)
  3. {
  4. ui->setupUi(this);
  6. QMenu *helpMenu = new QMenu("Help", this);
  7. menuBar()->addMenu(helpMenu);
  8. QAction *helpAction = helpMenu->addAction("Help index", this, SLOT(openHelp()));
  9. helpAction->setShortcut(QKeySequence::HelpContents);
  10. }

I tried also with an event filter in the dialog and in the application, but when i press under mac the Command-? or under windows F1 i see the event for the Command key but not for the ? key. I don't understand who is eating this key press.

Someone can explain me where the error is? Is these a way to connect QKeySequence::HelpContents to the help button in a dialog?