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

拈花ヽ惹草 提交于 2019-12-23 02:29:57

问题


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




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




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);



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




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.

回答1:


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.



来源:https://stackoverflow.com/questions/27615175/how-to-make-right-to-left-language-eg-arabic-characters-behave-like-left-to-ri

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!