Clarify that QKeyEvent::text() may return non-printable characters

This is the case for keys such as Qt::Key_Delete ("\u007F"),
and Qt::ControlModifier + Qt::Key_C ("\u0003") on Windows and XCB,
as well as potentially any key event on macOS when IM is not enabled,
as of 705665957b.

We can not filter QKeyEvent text() based on QChar::isPrint() or
similar, as there might e.g. be valid printable text in the private
use area, depending on the script and available fonts.

See QInputControl::isAcceptableInput() for some of this complexity.

Task-number: QTBUG-106393
Change-Id: I84d7ed86f57c1b605ac512d0f7ab66f6a11ed7bb
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
bb10
Tor Arne Vestbø 2022-12-02 12:37:48 +01:00
parent 2c78c5d456
commit 419cf9245a
1 changed files with 6 additions and 5 deletions

View File

@ -1440,12 +1440,13 @@ Q_IMPL_EVENT_COMMON(QKeyEvent)
Returns the Unicode text that this key generated.
Return values when modifier keys such as
Shift, Control, Alt, and Meta are pressed
differ among platforms and could return an empty string.
The text is not limited to the printable range of Unicode
code points, and may include control characters or characters
from other Unicode categories, including QChar::Other_PrivateUse.
\note \l key() will always return a valid value,
independent of modifier keys.
The text may also be empty, for example when modifier keys such as
Shift, Control, Alt, and Meta are pressed (depending on the platform).
The key() function will always return a valid value.
\sa Qt::WA_KeyCompression
*/