I'm trying to capture key events in my QPlainTextEdit that's inside of a QDialog widget.

Setup:

MainWindow has a push button. Pressing this button opens the dialog (MyDialog) which has the QPlainTextEdit (textEdit) inside it. This was designed in the Designer and I reference the .ui file rather than building it from code.

Details:

I've seen people say 'subclass the widget and reimplement the keyPressEvent'. The problem is, no one goes into detail of how, exactly, to subclass the QPlainTextEdit object. I've tried the following:

MyDialog.h
Qt Code:
  1. class MyDialog : public QDialog, public QPlainTextEdit
  2. {
  3. Q_OBJECT
  4. ...
To copy to clipboard, switch view to plain text mode 

MyDialog.cpp
Qt Code:
  1. MyDialog::MyDialog(QWidget *parent) :
  2. QDialog(parent), QPlainTextEdit(parent),
  3. ui(new Ui::MyDialog)
  4. {
  5. ...
To copy to clipboard, switch view to plain text mode 

But this gives me errors on essentially everything.
'ambiguous access of connect'
'connect identifier not found'
'show identifier not found'
etc.

I've also tried the following:

MyDialog.cpp
Qt Code:
  1. #include <QPlainTextEdit>
  2.  
  3. MyDialog::MyDialog ...
  4.  
  5. QPlainTextEdit::keyPressEvent(QKeyEvent *event) {
  6. ...
  7. }
To copy to clipboard, switch view to plain text mode 

But this traps all keys and doesn't send them to the parent control and I'm also guessing this is completely wrong. I've tried adding:

MyDialog.cpp
Qt Code:
  1. QPlainTextEdit::keyPressEvent(QKeyEvent *event) {
  2. ...
  3. QWidget::keyPressEvent(event);
  4. //or
  5. event->ignore();
  6. }
To copy to clipboard, switch view to plain text mode 

But that doesn't work either. I've tried reimplementing the keyPressEvent for MyDialog:

Qt Code:
  1. MyDialog::keyPressEvent(QKeyEvent *event) {
  2. cout << "dialog event" << endl;
  3. event->ignore();
  4. //or
  5. QDialog::keyPressEvent(event);
  6. }
To copy to clipboard, switch view to plain text mode 

But nothing gets passed on. I see the 'dialog event' in the console, so it is activating, but no event is passed on and the keyboard input is never displayed. I'm all out of ideas and no matter what I search for I cannot find an example or explanation of what I'm trying to do.

Thanks.