title: How to send a key event to a qwidget in a QDialog
body: <p>I am trying to create a dialog that returns a double, similar to a QInputDialog, but with numeric buttons included in the dialog.  It is for an embedded system with no keyboard.  </p>
  
  <p>The problem is that the QDoubleSpinBox never reacts to key presses/releases.  The dialog itself is receiving the key events.  I tried calling event->ignore() in keyPressEvent() and keyReleaseEvent(), without success.  Also tried calling QApplication::processEvents(), without success.</p>
  
  <p>I am using Qt 4.8 running on Linux on an embedded ARM processor.</p>
  
  <p>NumericDialog.h</p>
  
  <pre><code>#ifndef NUMERICDIALOG_H
  #define NUMERICDIALOG_H
  
  #include &lt;QDialog&gt;
  #include &lt;QSignalMapper&gt;
  
  namespace Ui {
  class NumericDialog;
  }
  
  class NumericDialog : public QDialog
  {
     Q_OBJECT
  
  public:
     explicit NumericDialog(QWidget *parent = 0);
     ~NumericDialog();
  
     void keyPressEvent(QKeyEvent *event);
     void keyReleaseEvent(QKeyEvent *event);
  
     void SetMax(double max);
     void SetMin(double min);
     void SetValue(double value);
     void SetSuffix(QString suffix);
     void SetTrimEnable(bool enable);
  
  private slots:
     void ButtonClicked(int key);
  
  private:
     Ui::NumericDialog *ui;
  
     QSignalMapper _SignalMapper;
  };
  
  #endif // NUMERICDIALOG_H
  </code></pre>
  
  <p>NumericDialog.cpp</p>
  
  <pre><code>#include "NumericDialog.h"
  #include "ui_NumericDialog.h"
  
  #include &lt;QKeyEvent&gt;
  #include &lt;QDebug&gt;
  
  
  NumericDialog::NumericDialog(QWidget *parent) :
     QDialog(parent),
     ui(new Ui::NumericDialog)
  {
     ui-&gt;setupUi(this);
  
     this-&gt;setFocusPolicy(Qt::NoFocus);
     ui-&gt;doubleSpinBox-&gt;setFocusPolicy(Qt::StrongFocus);
     ui-&gt;doubleSpinBox-&gt;setFocus();
  
     // Map signals, so we can use one slot for all buttons
     _SignalMapper.setMapping(ui-&gt;button0, '0');
     _SignalMapper.setMapping(ui-&gt;button1, '1');
     _SignalMapper.setMapping(ui-&gt;button2, '2');
     _SignalMapper.setMapping(ui-&gt;button3, '3');
     _SignalMapper.setMapping(ui-&gt;button4, '4');
     _SignalMapper.setMapping(ui-&gt;button5, '5');
     _SignalMapper.setMapping(ui-&gt;button6, '6');
     _SignalMapper.setMapping(ui-&gt;button7, '7');
     _SignalMapper.setMapping(ui-&gt;button8, '8');
     _SignalMapper.setMapping(ui-&gt;button9, '9');
     _SignalMapper.setMapping(ui-&gt;buttonDot, '.');
  
     _SignalMapper.setMapping(ui-&gt;buttonBS, Qt::Key_Backspace);
     _SignalMapper.setMapping(ui-&gt;buttonEnter, Qt::Key_Enter);
     _SignalMapper.setMapping(ui-&gt;buttonCancel, Qt::Key_Cancel);
     _SignalMapper.setMapping(ui-&gt;buttonUp, Qt::Key_Up);
     _SignalMapper.setMapping(ui-&gt;buttonDown, Qt::Key_Down);
  
  
     connect(ui-&gt;button0, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button1, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button2, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button3, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button4, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button5, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button6, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button7, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button8, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;button9, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;buttonDot, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
  
     connect(ui-&gt;buttonBS, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;buttonEnter, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;buttonCancel, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;buttonUp, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
     connect(ui-&gt;buttonDown, SIGNAL(clicked()), &amp;_SignalMapper, SLOT(map()));
  
     connect(&amp;_SignalMapper, SIGNAL(mapped(int)),this, SLOT(ButtonClicked(int)));
  
  
  }
  
  NumericDialog::~NumericDialog()
  {
     delete ui;
  }
  
  void NumericDialog::keyPressEvent(QKeyEvent *event)
  {
     qDebug() &lt;&lt; "Dialog got key press" &lt;&lt; event-&gt;text();
  
     QDialog::keyPressEvent(event);
  }
  
  void NumericDialog::keyReleaseEvent(QKeyEvent *event)
  {
     qDebug() &lt;&lt; "Dialog got key release" &lt;&lt; event-&gt;text();
  
     QDialog::keyReleaseEvent(event);
  }
  
  void NumericDialog::SetMax(double max)
  {
     ui-&gt;doubleSpinBox-&gt;setMaximum(max);
     ui-&gt;labelMax-&gt;setText(QString("%1").arg(max));
     ui-&gt;progressBar-&gt;setMaximum(max);
  }
  
  void NumericDialog::SetMin(double min)
  {
     ui-&gt;doubleSpinBox-&gt;setMinimum(min);
     ui-&gt;labelMin-&gt;setText(QString("%1").arg(min));
     ui-&gt;progressBar-&gt;setMinimum(min);
  }
  
  void NumericDialog::SetValue(double value)
  {
     ui-&gt;doubleSpinBox-&gt;setValue(value);
     ui-&gt;progressBar-&gt;setValue(value);
  }
  
  void NumericDialog::SetSuffix(QString suffix)
  {
     ui-&gt;doubleSpinBox-&gt;setSuffix(suffix);
  }
  
  void NumericDialog::ButtonClicked(int key)
  {
  
     switch(key)
     {
     case Qt::Key_Enter:
        break;
     case Qt::Key_Cancel:
        break;
     case Qt::Key_Up:
        break;
     case Qt::Key_Down:
        break;
  
     default:
        QKeyEvent keyPress(QEvent::KeyPress, key, Qt::NoModifier, QString(QChar(key)));
        qDebug() &lt;&lt; keyPress.text();
        QApplication::sendEvent(ui-&gt;doubleSpinBox, &amp;keyPress);
  
        QKeyEvent keyRelease(QEvent::KeyRelease, key, Qt::NoModifier, QString(QChar(key)));
        qDebug() &lt;&lt; keyRelease.text();
        QApplication::sendEvent(ui-&gt;doubleSpinBox, &amp;keyRelease);
  
        //QApplication::processEvents();
        break;
     }
  }
  </code></pre>
  
  <p>When I click on the number '9' button, the console output is:</p>
  
  <p>"9"<br>
  "9"<br>
  Dialog got key release "9"</p>
  
  <p>When I click on the Backspace button, the console output is:</p>
  
  <p>" "
  Dialog got key press " "
  " "
  Dialog got key release " " </p>
  
  <p>There are no changes to the value in the doubleSpinBox.  How do I get the key events to the doubleSpinBox?</p>
  
  <p>Thanks,
  Mary</p>