[Interest] Preventing ^2 from being converted to a superscript 2

Thiago Macieira thiago.macieira at intel.com
Sat Jul 25 04:21:59 CEST 2026


On Friday, 24 July 2026 12:45:07 Pacific Daylight Time Ben Haller via Interest 
wrote:
> In the language being edited, ^ is the exponentiation operator, so the
> user wants to type "x^2" and have that mean "x squared" in the language
> on question.  An issue recently arose where some of my users on Linux
> would type the "^2" and it would be turned into a superscripted 2 (!).

Cannot reproduce in the widgetgallery example, Qt 6.13, Wayland and X11 
(XWayland), using no special input method.

Are you sure your users are using the asciicircum key, not a dead_circumflex? 
Have them run xev and press the key. If it prints:

KeyPress event, serial 39, synthetic NO, window 0x1200001,
    root 0x43a, subw 0x0, time 130046808, (2009,-1014), root:(3839,76),
    state 0x91, keycode 15 (keysym 0x5e, asciicircum), same_screen YES,

Then we have to investigate. What input method are they using?

If it prints

KeyPress event, serial 39, synthetic NO, window 0x1200001,
    root 0x43a, subw 0x0, time 130081096, (2009,-1014), root:(3839,76),
    state 0x11, keycode 15 (keysym 0xfe52, dead_circumflex), same_screen YES,

Then it's expected because it's a dead key. If you don't want it to affect the 
next key, press space.. <dead_circumflex> followed by a number will produce 
superscripts: ¹²³⁴⁵⁶⁷⁸⁹⁰. There are also ⁽ and ⁾. The same can be accomplished 
by pressing <Compose> <asciicircum> and a number. Likewise, 
<Compose>,<underscore> followed by a number will produce subscripts: 
₁₂₃₄₅₆₇₈₉₀₍₎.

> My question: how can I customize my QPlainTextEdit subclass to prevent
> this?

It's not QPlainTextEdit's doing. This happens much deeper. If the user is 
using an input method, then the translation happens there. You'll have to work 
out with the input methods (all of them).

If there is no input method, it might be inside Qt: deep inside the XCB plugin 
(for X11) and Wayland plugin (for Wayland) that translate the sequence of keys 
to a symbol. They are obeying the xkb keyboard and Composition rules. If you 
REALLY want to do this, you'll need to patch the libraries and recompile.

>  I'd also like to not interfere with typing of accented
> characters, emojis, etc.; I just want to prevent this specific feature
> from activating in my code view, because the '^' character is
> significant and I don't want it to be re-interpreted by the OS

Why do you want to interfere with other users' ability to type "O(n²)" in a 
comment?

-- 
Thiago Macieira - thiago.macieira (AT) intel.com
  Principal Engineer - Intel DCG - Platform & Sys. Eng.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5176 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20260724/fa15f9da/attachment.bin>


More information about the Interest mailing list