[Interest] Make a specific Unicode glyph wider in a QTextLayout

Wang Gary wzc782970009 at gmail.com
Mon Dec 16 03:55:27 CET 2024


> But since you want to edit it, it is probably too cumbersome. Of your two
> suggested approached I think the QTextLayout has the best chance of working.

So do you mean subclassing QTextLayout and accessing the private APIs?
I also think it might be the way to do so but I'm just not sure if
that's the intended
usage of that set of APIs for this purpose.

> You can always add another model level.
>
> Data model -> View model -> View
>
> ...
>
> I would look up how QtCreator and KWrite handles emoticons, and similar fancy
> text tricks.

Well, KTextEditor is the component used by KWrite, which is what I am trying to
modify. I also didn't find any view model sit between the data source and the
render logic so I'm still not sure if it's actually needed. The
"replacing" approach
also didn't address the original issue that I want to adjust a
character's width to
a specific value.

> Emoticons are when text smileys : ) are replaced at editing time
> with emojis. This type of replacement sounds similar to what you need.

AFAIK KWrite (KTextEditor) didn't handle emojis as a special case. emojis are
treated as regular Unicode glyphs and rendered as-is, without any special care.

Some other KDE apps (e.g. NeoChat) did handle emojis specially, by finding
the related emoji unicode characters and replacing the characters to force these
characters using a given font because of QTBUG-85744 and QTBUG-111801,
but they are more of a viewer than editor, which don't have to deal with editing
and syntax highlighting.

Best regards
Gary


More information about the Interest mailing list