install EventFilter on QWidget (qt4.4.3/kde4)

Giancarlo picture Giancarlo · Dec 20, 2008 · Viewed 9.6k times · Source

I have a K* window, and within it, a widget which needs the events filtered.

For example I do not want the possibility of clicking it...

How can I do that?

Have I to use eventfilters? In this case, what's the best way?


but my problem is that I can't subclass my widget,because it's a TerminalInterface->widget(), not an object like others :\

Answer

aseigo picture aseigo · Dec 20, 2008

Besides the setEnabled sledgehammer approach in the first answer, there are two other approaches, one of which is to use eventfilters.

The other is to subclass the widget, and then reimplement, say, the mouse* events. Simply leaving them empty will prevent any mouse interaction. So:

MyWidget : public QSomeWidget { Q_OBJECT public: MyWidget(QWidget *parent);

protected: void mousePressEvent(QMouseEvent *) {} .. etc .. };