Hello!
I have this "TableHist" class where i implement a mousePressEvent. I promoted a QTableWidget to "TableHist". When i click on this table with right, left and middle button, that table should do different things. I say "should do" because i want to access an object created in another class first, but i don't know how to get access. How can i do that?


Qt Code:
  1. #ifndef TABLEHIST_H
  2. #define TABLEHIST_H
  3.  
  4. #include <iostream>
  5. #include <QMouseEvent>
  6. #include <QTableWidget>
  7.  
  8. // Object i want to access.
  9. #include "database.h"
  10.  
  11. using namespace std;
  12.  
  13. class TableHist : public QTableWidget {
  14. public:
  15. TableHist(QWidget *parent = 0);
  16. virtual void mousePressEvent(QMouseEvent *event);
  17. };
  18.  
  19. #endif // TABLEHIST_H
To copy to clipboard, switch view to plain text mode 

Qt Code:
  1. #include "tablehist.h"
  2.  
  3. TableHist::TableHist(QWidget* parent ) : QTableWidget( parent ) {}
  4.  
  5. void TableHist::mousePressEvent(QMouseEvent *event) {
  6.  
  7. QTableWidget::mousePressEvent( event );
  8. if(event->button( ) == Qt::RightButton) {
  9. //Do something with that object.
  10. }
  11. else if (event->button( ) == Qt::LeftButton) {
  12. //Do something with that object.
  13. }
  14. else {
  15. //Do something with that object.
  16. }
  17.  
  18. }
To copy to clipboard, switch view to plain text mode 

Thanks!