views:

796

answers:

4

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?

A: 

QWidget has an enabled property. Just call widget->setEnabled(false) and this will prevent it from accepting mouse clicks. It may also modify its appearance: for example a QPushButton will be grayed out.

Event Filters sound like overkill for what you want.

Mark Beckwith
It isn't the thing I want. I need to *filter* the events, not to disable them...
Giancarlo
+1  A: 

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 .. };

aseigo
but my problem is that I can't subclass my widget,because it's a TerminalInterface->widget()
Giancarlo
+1  A: 

It looks like eventFilter() is what you want.

Here's the section of Qt docs that talk about it: Event Filters

Basically you have to create a class that inherits QObject and then implement the virtual function eventFilter(). Then call the installEventFilter() method on the object that you want to filter with the filter as a parameter.

Mark Beckwith
A: 

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

Giancarlo