robgeek
8th December 2015, 17:29
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?
#ifndef TABLEHIST_H
#define TABLEHIST_H
#include <iostream>
#include <QMouseEvent>
#include <QTableWidget>
// Object i want to access.
#include "database.h"
using namespace std;
class TableHist : public QTableWidget {
public:
TableHist(QWidget *parent = 0);
virtual void mousePressEvent(QMouseEvent *event);
};
#endif // TABLEHIST_H
#include "tablehist.h"
TableHist::TableHist(QWidget* parent ) : QTableWidget( parent ) {}
void TableHist::mousePressEvent(QMouseEvent *event) {
QTableWidget::mousePressEvent( event );
if(event->button( ) == Qt::RightButton) {
//Do something with that object.
}
else if (event->button( ) == Qt::LeftButton) {
//Do something with that object.
}
else {
//Do something with that object.
}
}
Thanks!
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?
#ifndef TABLEHIST_H
#define TABLEHIST_H
#include <iostream>
#include <QMouseEvent>
#include <QTableWidget>
// Object i want to access.
#include "database.h"
using namespace std;
class TableHist : public QTableWidget {
public:
TableHist(QWidget *parent = 0);
virtual void mousePressEvent(QMouseEvent *event);
};
#endif // TABLEHIST_H
#include "tablehist.h"
TableHist::TableHist(QWidget* parent ) : QTableWidget( parent ) {}
void TableHist::mousePressEvent(QMouseEvent *event) {
QTableWidget::mousePressEvent( event );
if(event->button( ) == Qt::RightButton) {
//Do something with that object.
}
else if (event->button( ) == Qt::LeftButton) {
//Do something with that object.
}
else {
//Do something with that object.
}
}
Thanks!