Fix spacebar panning not working after focus leaves the map view by Oval17 · Pull Request #4338 · mapeditor/tiled (original) (raw)

@Oval17

SpaceBarEventFilter was installed on MainWindow, so it only received Space key events that propagated up to the main window. When another widget (e.g. the Layers dock tree view) had keyboard focus and consumed the Space key press, the filter never saw it, leaving mSpacePressed false. The first click in the map viewport would therefore activate the current tool instead of panning.

Fix by installing the filter on qApp instead, which receives all key events dispatched in the application regardless of which widget holds focus. A guard is added to skip Space events sent to widgets with WA_InputMethodEnabled (QLineEdit, QPlainTextEdit, etc.) so that typing spaces in text fields does not accidentally enable pan mode.

bjorn

requested changes Feb 24, 2026

@bjorn

This way we get the press/release events before they might get eaten by an input widget.

Since the MainWindow hasn't created its window yet by the time the SpaceBarEventFilter instance is created, we're installing another event filter to intercept the QEvent::WinIdChange event.

We don't want to install the event filter on the application instance, because it will mean it receives the event for every target it is delivered to.

Oval17

@bjorn

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})