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

Max Paperno max-l at wdg.us
Sat Jul 25 03:44:14 CEST 2026


Hi Ben,

> I think, instead, that this Linux feature is turning "^2" into the 
> Unicode superscripted 2 character

I'm guessing this is more likely a keyboard layout feature, and could 
happen in any OS. Specifically, a "dead keys" type layout where some 
physical keys don't provide any output until a subsequent key (or 
series) is pressed.  I'm not sure of course, w/out knowing what your 
affected users actually experience, but it seems more likely than an 
OS-wide feature (that's why layouts exist in thee first place, after all).

If that's the case, I'm not sure your application can do anything about 
it (literally, since it won't see the "^" key being pressed at all).  I 
guess you could filter for Unicode superscript numerals and convert them 
back... but that seems awkward and error prone, and might not be the 
only case that causes issues with different layouts.

Some languages require those types of layouts, though sometimes there 
are alternative layouts available (eg. geared more towards programmers). 
Other user-side workarounds are to type two "^" characters in a row 
(should output a literal "^") or add a space between caret and number 
(more readable code anyway  ;-)  ).

I'd certainly be curious to know if dead keys aren't the issue here.

Cheers,
-Max

Ithaca, NY


On 7/24/2026 3:45 PM, Ben Haller via Interest wrote:
> Hi all! I've got a Qt project that contains a code editor.  The code 
> editor is based on QPlainTextEdit, with a bit of subclassing for 
> syntax highlighting and things of that sort -- code editor-y 
> functionality.  I doubt any of that subclassing is relevant to the 
> question at hand.
>
> 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 (!).  I guess this is some Linux feature to make it 
> easier to type exponents and such.  Which is fine, but obviously 
> inappropriate for a code editor; the user needs to be able to type 
> "^2" and have it stay "^2" even if, in other apps on that platform, it 
> appropriately gets changed to a superscipted 2.
>
> Note that the QPlainTextEdit is plain text, of course; I don't think 
> this is rich text somehow creeping into the plain text view.  I think, 
> instead, that this Linux feature is turning "^2" into the Unicode 
> superscripted 2 character (https://unicode-explorer.com/c/00B2).
>
> My question: how can I customize my QPlainTextEdit subclass to prevent 
> this?  Is there a hook or a setting somewhere?  I assume that, e.g., 
> Qt Creator manages to prevent these kinds of shenanigans on all 
> platforms, so maybe I'm asking somebody who knows the Qt Creator code 
> well to advise on what they did there. It is quite possible that these 
> users could turn off this feature in a Linux prefs panel somewhere, 
> but I don't want to ask them to have to do that; they should be able 
> to have the OS feature enabled, and yet I should be able to turn it 
> off in my code view. 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
>
> Thanks for any tips!
>
> Cheers,
> -B.
>
> Benjamin C. Haller
> Messer Lab
> Cornell University
>
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> https://lists.qt-project.org/listinfo/interest



More information about the Interest mailing list