问题描述
Qt
提供了一种强大的自适应方式来处理 left-to-right
语言和 right-to-left
语言文本.但是我遇到了解决我的目标时遇到的问题.
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.
图片No.1我想要得到的东西
Picture No.1 What I want to get
第2张图片粘贴到基于QTextEdit
的小部件时,我得到的是第1张图片
Picture No.2 What I got when paste to my QTextEdit
based widget what picture no.1 shows
第3张图片,当我将文本方向设置为从左到右时,我得到了什么,如下所示:
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.
图片No.4当我尝试将文本添加到终端时,我得到了什么
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.
推荐答案
Unicode提供了 Directional Formatting Characters
,而 Qt
对此提供了很好的支持.这个想法来自@ VahidN.我的问题已部分通过这种方式解决,现在它可以正确显示双向字符串.
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.
这篇关于如何使从右到左的语言(例如阿拉伯语)字符的行为像在qt中从左到右的语言一样?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!