Qt Code:
  1. #include "mainwindow.h"
  2. #include "ui_mainwindow.h"
  3.  
  4.  
  5. MainWindow::MainWindow(QWidget *parent) :
  6. QMainWindow(parent),
  7. ui(new Ui::MainWindow)
  8. {
  9. ui->setupUi(this);
  10.  
  11.  
  12.  
  13. }
  14.  
  15. MainWindow::~MainWindow()
  16. {
  17. delete ui;
  18. }
  19. class Mouse : public QObject
  20. {
  21. Q_OBJECT
  22.  
  23.  
  24. protected:
  25. bool eventFilter(QObject *obj, QEvent *event);
  26. };
  27. Mouse *mouse = new Mouse();
  28. bool Mouse::eventFilter(QObject *obj, QEvent *event)
  29. {
  30. if (event->type() == QEvent::MouseButtonPress) {
  31.  
  32. return true;
  33. } else {
  34. // standard event processing
  35. return QObject::eventFilter(obj, event);
  36. }
  37. }
  38. QLabel*label=new QLabel();
  39. label->installEventFilter(mouse);
To copy to clipboard, switch view to plain text mode 


I wanted to install event filter in Qlabel of my ui application ....I have posted the code above but I am having problem with it...I might be declaring the class in wrong section please help me how to install eventfilter in qlabel for mouseevent handling