Thanks for your help! I tried to make a test program with a qtablewidget, but did not work! I created an UI with a QWidget a
I created a derived class from QTableWidget and override mousePressedEvent. When i click on the table nothing happens. I believe this is happening because i didn't call mousePressedEvent anywhere, but i don't know where to call it.
Take a look at the code, please. What is wrong?
#ifndef TESTEVT_H
#define TESTEVT_H
#include <iostream>
#include <QMouseEvent>
#include <QTableWidget>
using namespace std;
public:
TestEvt( );
};
#endif // TESTEVT_H
#ifndef TESTEVT_H
#define TESTEVT_H
#include <iostream>
#include <QMouseEvent>
#include <QTableWidget>
using namespace std;
class TestEvt : public QTableWidget {
public:
TestEvt( );
virtual void mousePressEvent(QMouseEvent *event);
};
#endif // TESTEVT_H
To copy to clipboard, switch view to plain text mode
#include "testevt.h"
TestEvt::TestEvt( ) {
cout << "Object created." << endl;
}
if(event->button( ) == Qt::LeftButton)
cout << "Left Button Clicked." << endl;
}
#include "testevt.h"
TestEvt::TestEvt( ) {
cout << "Object created." << endl;
}
void TestEvt::mousePressEvent(QMouseEvent *event) {
if(event->button( ) == Qt::LeftButton)
cout << "Left Button Clicked." << endl;
}
To copy to clipboard, switch view to plain text mode
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow( );
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
namespace Ui {
class MainWindow;
}
class MainWindow : public QMainWindow {
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow( );
private:
Ui::MainWindow *ui;
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
#include "mainwindow.h"
#include "testevt.h"
#include "ui_mainwindow.h"
ui->setupUi( this );
TestEvt evt;
}
MainWindow::~MainWindow( ) {
delete ui;
}
#include "mainwindow.h"
#include "testevt.h"
#include "ui_mainwindow.h"
MainWindow::MainWindow(QWidget *parent) : QMainWindow( parent ), ui(new Ui::MainWindow) {
ui->setupUi( this );
TestEvt evt;
}
MainWindow::~MainWindow( ) {
delete ui;
}
To copy to clipboard, switch view to plain text mode
Bookmarks