Good evening,

I have code as follows:

Qt Code:
  1. MChat::MChat(QMainWindow *parent) : QMainWindow(parent) {
  2. setupUi(this);
  3. inputChat->installEventFilter(this);
  4. connect(reinterpret_cast<QObject*>(this), SIGNAL(pressedReturn()),
  5. reinterpret_cast<QObject*>(sendButton), SLOT(animateClick()));
  6. }
  7.  
  8. bool MChat::eventFilter(QObject *obj, QEvent *event) {
  9. if (event->type() == QEvent::KeyPress) {
  10. QKeyEvent *keyEvent = reinterpret_cast<QKeyEvent *>(event);
  11. if ( keyEvent->key() == Qt::Key_Return ) {
  12. emit pressedReturn();
  13. return true;
  14. }
  15. else {
  16. // continue standard event processing
  17. return QObject::eventFilter(obj, event);
  18. }
  19. }
  20. }
To copy to clipboard, switch view to plain text mode 

I personally don't think this is good. I'd like to have the eventFilter as a method of inputChat. But to do this I'd have to directly edit the code generated by uic. At least, that's the only way I know. Perhaps someone could show me a better way?