Project

General

Profile

Actions

Improvements #14321

open
MS

Clarification WApplication::globalKeyWentDown/Up and WDialog::keyWentDown/Up

Improvements #14321: Clarification WApplication::globalKeyWentDown/Up and WDialog::keyWentDown/Up

Added by Michael Seibt 7 months ago. Updated 20 days ago.

Status:
New
Priority:
Normal
Assignee:
-
Target version:
-
Start date:
02/10/2026
Due date:
% Done:

0%

Estimated time:

Description

Affected: docs and concept of Wt 4.12.2 (and former versions)
split from Improvements #13791: WApplication::globalKeyWentDown dead as long as WMenu focused by mouse click

from https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WApplication.html#a0a9652fc0d0cbebca7966f98454b078a:

Wt::WApplication::globalKeyWentDown()
Event signal emitted when a keyboard key is pushed down.
The application receives key events when no widget currently has focus. Otherwise, key events are handled by the widget in focus, and its ancestors.

from https://www.webtoolkit.eu/wt/doc/reference/html/classWt_1_1WDialog.html#a7da2f1f110190cc345b34ba4a6f35301:

Wt::WDialog::keyWentDown()
Event signal emitted when a keyboard key is pushed down.
The event will be triggered if nothing in the WDialog has focus

  1. Both docs are not exact. "no widget" / "nothing" might mean "no WFormWidget" or some other base class. The events do fire if f.i. a WTableView is focused.
  2. In UI frameworks, globalKeyWentDown usually fires on all key presses regardless of the focus (and provides means to intercept keypresses).
    One can simulate this to a certain degree by adding the handler to all widgets. This is error-prone, pretty inconvenient and not feasible for e.g. WMenu because it does not expose such signals.
  3. I see no difference between these signals of WApplication and WDialog. Why different names?

Files

main.cpp (16.6 KB) main.cpp Michael Seibt, 02/10/2026 04:10 PM

MS Updated by Michael Seibt 7 months ago Actions #1

attached WDialog with different widgets and trace output from both key handlers

RM Updated by Romain Mardulyn 20 days ago Actions #2

  1. No widget means no WWidget. If a WTableView is focused and WApplication::globalKeyWentDown() is emitted, it is a bug (Note that a WTableView being focused has nothing to do with the fact that an element inside the WTableView is selected).
  2. WMenu cannot be focussed, WMenuItem are what is being focussed, and that class is inherit from WContainerWidget, which itself inherit from WInteractWidget, so you can have a WMenuItem react to a key pressed when it has the focus. Also, most of what you do not get via WApplication::globalKeyWentDown(), you can get with WApplication::root()::keyWentDown().

MS Updated by Michael Seibt 20 days ago Actions #3

Hi Romain,

thank you for the clarification!
I missed WApplication::root()::keyWentDown(). I am switching to it.

Actions

Also available in: PDF Atom