waterd
waterd

Reputation: 651

How to make right-to-left language (eg.Arabic) characters behave like left-to-right languages do in qt?

Qt provides a powerful adaptive way to deal with left-to-right languages and right-to-left languages texts.But I encounter my problems dealing with my goals.


Picture No.1 What I want to get
image no.1


Picture No.2 What I got when paste to my QTextEdit based widget what picture no.1 shows
image no.2


Picture No.3 What I got when I set text-direction to left-to-right as shown below:

QTextDocument *doc = ui->textEdit->document();
QTextOption textOption = doc->defaultTextOption();
textOption.setTextDirection(Qt::LeftToRight);
doc->setDefaultTextOption(textOption);
ui->textEdit->setDocument(doc);

image no.3

Making it left-to-right aligned is not that hard,
but the result differs from what picture no.1 shows.

Picture No.4 What I got when I try appending texts to the terminal
image no.4


What I want to achieve is the fact that it shows like picture no.1 does,
and key-strikes make texts appended to the terminal
when the existting texts is terminated by a Arabic notation.
In a word,all I want is that it behave like left-to-right languages do
whether it contains right-to-left language characters or not.

Upvotes: 3

Views: 2046

Answers (1)

waterd
waterd

Reputation: 651

Unicode provides Directional Formatting Characters,and Qt supports it well.The idea comes from @VahidN.My problem is solved partly via this way,now it display bidirection string properly.

QString(QChar(0x200E))+strText; //LRM
QString(QChar(0x202D)) + strText + QString(QChar(0x202C)); //LRO...PDF

Before this question I answered another one,which maybe helpful for finding your own solution.

Upvotes: 4

Related Questions