Ask Your Question

Revision history [back]

Hi Authur,

I managed to do that by using a QEventFilter on the plugin's widget object.

SamplePlugin.h:

class SamplePlugin : public rqt_gui_cpp::Plugin {
Q_OBJECT
public:
    ...
    bool eventFilter(QObject *target, QEvent *event);
    ...
}

SamplePlugin.cpp:

...
void SamplePlugin::initPlugin(qt_gui_cpp::PluginContext &context) {
     widget = new QWidget();
     ui.setupUi(widget);
     context.addWidget(widget);

     widget->installEventFilter(this);
     widget->setFocus();
     ...
}
...
bool SamplePlugin::eventFilter(QObject *target, QEvent *event) {
    if(event->type() == QEvent::KeyPress)
        std::cout << "Key pressed!" << std::endl;
    return rqt_gui_cpp::Plugin::eventFilter(target, event);
}
...

I found this out on rover_gui_plugin.cpp on link text.