I tried setting up both a mouse and keyboard event to try to learn a bit more about Qt and C++. The mouse event is to make the centre mouse button available for paste and the keyboard event to mean when the return key is pressed in a tablewidget the cursor moves to the next cell down. Both compile neither work and no errors are given. The mouse would be nice the return key is annoying and hence more important. Where am I going wrong?

Class and function defs
Qt Code:
  1. public:// public
  2. void moveDown();
  3.  
  4. protected: // protected
  5. void x11mouseEvent(QMouseEvent *event);
  6. bool returnKey(QKeyEvent* event);
  7. private:
  8. QTableWidget *table;
  9. QEvent *event;
To copy to clipboard, switch view to plain text mode 

function code

Qt Code:
  1. // centre mouse uses an existing paste() function
  2.  
  3. void Spreadsheet::x11mouseEvent(QMouseEvent *event)
  4.  
  5. {
  6. QClipboard *clipboard = QApplication::clipboard();
  7. if (event->button()==Qt::MidButton && clipboard->supportsSelection())
  8. {
  9. QString text = clipboard->text(QClipboard::Selection);
  10. paste(); // calls paste function for spreadsheet (this function works fine just not with centre mouse)
  11. }
  12. }
  13.  
  14. // cell down functions
  15.  
  16. void Spreadsheet::moveDown()
  17. {
  18.  
  19. int row=currentRow();
  20. row += 1;
  21. int column=currentColumn();
  22.  
  23. if (row>=RowCount) // check bounds are possible
  24. {
  25. row=0;
  26.  
  27. }
  28.  
  29. setCurrentCell(row, column);
  30.  
  31. }
  32. bool Spreadsheet::returnKey(QKeyEvent* event)
  33. {
  34. if (event->type()==QEvent::KeyPress)
  35. {
  36. QKeyEvent *keyEvent=static_cast<QKeyEvent *>(event);
  37. if ((keyEvent->key()==Qt::Key_Return) && (table->hasFocus()) ) // hasFocus probably not needed doesn't help
  38. {
  39. moveDown();
  40. return true;
  41. }
  42.  
  43. }
  44.  
  45. return QWidget::event(event);
  46. }
To copy to clipboard, switch view to plain text mode