2

I am using QTextEdit to display Arabic text, but there are tiny gaps between the letters when I justify the text.

Here's an example of how it looks:

in-between letters gap

And I highlighted the gaps in here:

Highlighted gaps

I tried changing:

  • Fonts.

  • Font weight.

  • Font size.

  • line wrap mode.

  • Font letter spacing (this one closed the gaps a little when i gave it a negative value, but it's not the solution).

  • Font word spacing.

  • Enabling/disabling kerning

But same problem.

1 Answers1

0

The problem is caused by applying justification on arabic letters that's meant for latin ones.

Arabic letters cannot have spaces between them, unlike latin letters, and since justifying text in QTextEdit seems to mess with letter spacing, it cannot be applied to arabic text, because it simply makes it look ugly and unpleasant to read because of the in between letters gaps.

One solution that seems to work partially, is to use the stretch metric of the used font. In my case, a value of 50 made the gaps almost completely disappear, but it's too tight.

QFont f=text->font();

f.setStretch(50);
f.setLetterSpacing(QFont::AbsoluteSpacing,-0.3);
f.setWordSpacing(2);
text->setFont(f);

You can also combine it with a custom letter and word spacing, it depends on your situation and how it affects your text.

You can take a look at the result, the difference is quite noticeable.

Before:

Text before applying the aforementioned solution

After:

Text after applying the aforementioned solution

Note: The proper way to solve this problem is to use an algorithm that inserts kashidas ('ـ') into the arabic text, instead of manipulating font metrics, but this is not available in qt, one has to do that on their own, which is not an easy task.