[Interest] Make a specific Unicode glyph wider in a QTextLayout
Wang Gary
wzc782970009 at gmail.com
Sun Dec 15 08:23:50 CET 2024
Hi,
I'm attempting to implement a feature in a plain text editor that similar
to Notepad++'s "show hidden characters", which allows toggle the visibility
of non-printable characters, like zero-width space, CR LF and so-on, which
look like this in Notepad++ (see the attachment for the sample document):
[image: image.png]
By looking at QTextLine and QTextLayout, it doesn't seems like there is a
way to specific a certain unicode glyph's width (to reserve the space so we
can then draw the character as visible glyphs manually). What comes to mind
are the following two approaches:
1. Subclass QTextLayout to override the behavior of `cursorToX()` and other
related functions.
By quickly take a look at this approach, it might be more complex than I
thought, which will require using Qt's private header to access
QTextEngine-related stuff.
2. Create a custom font that provides these characters, and ensure that
font will be used before any other fonts.
I'm not exactly sure if this method is possible though.
So the question is, what's the proper approach to implement such a feature
using Qt's public API? Do the mentioned two approaches sound right?
Thanks!
Gary
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20241215/b831309a/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: image.png
Type: image/png
Size: 8225 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20241215/b831309a/attachment.png>
-------------- next part --------------
aaaaaaa
a
a
​
 
More information about the Interest
mailing list