In a modal dialog i set the shortcut http://qt-project.org/doc/qt-4.8/QKeySequence::HelpContents to the help button, but this shortcut is not working, the button is not clicked if I press the corresponding shortcut.

Code:

  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 http://qt-project.org/doc/qt-4.8/QKeySequence::HelpContents 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.

Code:

  1. MainWindow::MainWindow(QWidget *parent) :
  2. QMainWindow(parent), ui(new Ui::MainWindow)
  3. {
  4. ui->setupUi(this);
  5.  
  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?

Thanks.