RightToLeft QTextEdit for Hebrew
I would like to use QT for a Hebrew speaking application.
I need to enter some text into a text area but since t's in hebrew
The text is being written Right to left
Specifically the cursor should blnk on the right side of the area on start.
Is it possible?
tnx,
hed
1 Attachment(s)
Re: RightToLeft QTextEdit for Hebrew
You can set the direction of a widget via QWidget::setLayoutDirection() and
QApplication::setLayoutDirection().
try this
Code:
#include <QtGui>
int main(int argc, char** argv)
{
edit->setLayoutDirection(Qt::RightToLeft);
edit->show();
return app.exec();
}
The result will look like this:
Attachment 2177
1 Attachment(s)
Re: RightToLeft QTextEdit for Hebrew
Tnx a lot,
Tried it and it works but still doesnt solve my problem.
because i need multiple lines edit and the same code you posted doesn't work for QTextEdit.
It behaves dffrently then QLineEdit:
Attached an image.
The lower is QLineEdit and the Middle one is QTextEdit which in which you can see the text s on the left.
Hed
Re: RightToLeft QTextEdit for Hebrew
One ugly but simple workaround would be using QTextEdit::setAlignment(Qt::Right); This may suffice if your edit is solely used for hebrew and all the text contained there should be right-aligned.
But You should use something better than this. I guess it is all about setting the right layout for the document, not the gui element that displays it.
Maybe these functions can be of some help to you:
Unfortunately I've never really done anything special with QTextDocuments so I am pretty clueless here.
Re: RightToLeft QTextEdit for Hebrew
Hi there,
first at all, could you precise if your want text aligned to right or just text should be entered from right to left while typing?
If the problem is an alignment, it can be set by QTextEdit::setAlignment(Qt::Right) but it's not dependent on language and can be set different for different paragraphes.
If you want text to be written right to left while typing, try settin system language to hebrew and text edit should deal with inverted insertion automatically[we have no additional methods for right-to-left languages and if application is run in hebrew text edits inserts chars before cursor when typing(except numbers which are typed normally, so text cursor have strange arrow that show text direction].
or am i missing something?
Please let me know if what qt does automatically for hebrew is incorrect(our application should deal with right-to-left languages, but we don't know any so we can't be sure is our software works properly with such languages)
Re: RightToLeft QTextEdit for Hebrew
I think you will have to sub-class QTextEdit and set the proper options in QTextOptions for the selected paragraph. I have done that for katePart (well, still not finished, but parts are working).
See this thread, and when my development setup will be available (my computer crahsed, and I had to re-install it from scratch) I will try to post some code here. Meanwhile, look at this thread:
http://www.progressive-comp.com/?l=k...4289516836&w=2
1 Attachment(s)
Re: RightToLeft QTextEdit for Hebrew
Quote:
Originally Posted by
mchara
If you want text to be written right to left while typing, try settin system language to hebrew and text edit should deal with inverted insertion automatically[we have no additional methods for right-to-left languages and if application is run in hebrew text edits inserts chars before cursor when typing(except numbers which are typed normally, so text cursor have strange arrow that show text direction].
Persian, like hebrew is written from right to left. Thus, the text typed in should be right-aligned. More so, if I have set the applications layoutDirection to Right to left as in this example:
Attachment 2182
As you can see the line edit behaves the way it should. The TextEdit however doesnt and the text is still left-aligned. This looks very out of place for persian text (and other rtl languages.)
It should however do that depending on the language typed in so that one paragraph can be persian, the next one english and so forth ... and all be aligned correctly irrespective of the layoutDirection.
In kde only kedit is smart enough to handle that correctly. kwrite and kate do not (which doesn't come as a surprise since they both are built upon katepart). I really hope kate will handle that correctly in the newer version.
For the sake of completeness, here's the code for the above example:
Code:
#include <QtGui>
{
Q_OBJECT
public:
cw->setLayout(lo);
setCentralWidget(cw);
}
};
int main(int argc, char** argv)
{
app.setLayoutDirection(Qt::RightToLeft);
MainWindow mw;
mw.show();
return app.exec();
}
#include "main.moc"