Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ESC to switch to default tool not working in humble. #1119

Open
Krzo99 opened this issue Jan 10, 2024 · 3 comments
Open

ESC to switch to default tool not working in humble. #1119

Krzo99 opened this issue Jan 10, 2024 · 3 comments
Labels
bug Something isn't working help wanted Extra attention is needed

Comments

@Krzo99
Copy link

Krzo99 commented Jan 10, 2024

In Rviz2, switching between tools with shortcuts works normally.
However, pressing ESC to switch back to the default tool doesn't work.

This error also happens, when I try to process keyPressEvent in a custom panel widget. When focused, normal keys work, but the ESC key is not captured. However, if I hold down the mouse button and press ESC, it is captured (using a custom eventFilter on QApplication.

class ESCKeyPressFilter : public QObject {
    Q_OBJECT
protected:
    bool eventFilter(QObject *obj, QEvent *event) override {
        if (event->type() == QEvent::KeyPress) {
            QKeyEvent *keyEvent = static_cast<QKeyEvent *>(event);
            if (keyEvent->key() == Qt::Key_Escape) {
                emit ESCPressed();
                return true;
            }
        }
        return QObject::eventFilter(obj, event);
    }

signals:
    void ESCPressed();
};

....

auto app = QApplication::instance();
    if (app != nullptr) {
        ESCKeyPressFilter *filter = new ESCKeyPressFilter();
        app->installEventFilter(filter);

        connect(filter, &ESCKeyPressFilter::ESCPressed, this, &TerrascoutPanel::onESCPressed);
    }

    setFocusPolicy(Qt::StrongFocus);

It looks like ESC key is being handled somewhere else. The only thing I could find is the "exit fullscreen" shortcut in visualization_frame.cpp

new QShortcut(Qt::Key_Escape, this, SLOT(exitFullScreen()));

Could this line be interrupting other ESC key presses?

My version of rviz2: ros-humble-rviz2/jammy,now 11.2.9-1jammy.20231207.081716 amd64

@audrow audrow added the help wanted Extra attention is needed label Jan 18, 2024
@audrow
Copy link
Member

audrow commented Jan 18, 2024

Hi @Krzo99, it's strange that it's not working. I wonder if you're right about the line.

If you have time, feel free to dig into this further and open a PR if you find a fix.

@audrow audrow added the bug Something isn't working label Jan 18, 2024
@Krzo99
Copy link
Author

Krzo99 commented Jan 22, 2024

I'll look into it when I have time, which I'm not sure when it'll be.
Keep you updated!

Update: The line new QShortcut(Qt::Key_Escape, this, SLOT(exitFullScreen())); is the culprit, when removed, the ESC key correctly switches selected tool back to default one.

@marip8
Copy link
Contributor

marip8 commented May 24, 2024

This was solved several years ago in the ROS1 Rviz: ros-visualization/rviz#1416. We could probably apply the same patch here fairly easily

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

3 participants