Question

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 :\

Was it helpful?

Solution

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

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top