ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
1

QKeyEvent with ROS Rqt??

asked 2017-03-13 05:35:53 -0500

Authur gravatar image

updated 2017-03-13 05:41:44 -0500

Hi everyone,

I want to get Keyboard state in Ros Rqt Plugin, I try to use QKeyEvent but it's not work. Although, when I try to use it in Qt Widgets Application, it's work.

I want to capture key state when program can do something else,

I follow that clip : here

My Code : here

Thanks you,

edit retag flag offensive close merge delete

Comments

rqt provides a way to hook your Qt programs to ROS. You should be able to handle QEvent and its child class events without any knowledge for ROS.

130s gravatar image 130s  ( 2017-06-10 21:42:12 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2017-06-10 16:25:28 -0500

asilvaigor gravatar image

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.

edit flag offensive delete link more

Question Tools

2 followers

Stats

Asked: 2017-03-13 05:35:53 -0500

Seen: 454 times

Last updated: Jun 10 '17