Results 1 to 7 of 7

Thread: RightToLeft QTextEdit for Hebrew

  1. #1
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: RightToLeft QTextEdit for Hebrew

    You can set the direction of a widget via QWidget::setLayoutDirection() and
    QApplication::setLayoutDirection().

    try this
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char** argv)
    4. {
    5. QApplication app(argc, argv);
    6. QLineEdit* edit = new QLineEdit;
    7. edit->setLayoutDirection(Qt::RightToLeft);
    8. edit->show();
    9. return app.exec();
    10. }
    To copy to clipboard, switch view to plain text mode 

    The result will look like this:
    right-to-left.jpg

  3. #3
    Join Date
    Jan 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default 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
    Attached Images Attached Images

  4. #4
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default 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:
    Qt Code:
    1. QTextEdit::document();
    2. QTextFormat::setLayoutDirection();
    To copy to clipboard, switch view to plain text mode 
    Unfortunately I've never really done anything special with QTextDocuments so I am pretty clueless here.

  5. #5
    Join Date
    Sep 2007
    Location
    Szczecin, Poland
    Posts
    153
    Thanks
    7
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default 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)
    See GrEEn (Graphics Effects Environment)
    http://sourceforge.net/project/platf...roup_id=232746
    a qt-based plugins oriented MDI image processing application(contains also qt plugins like styles & imageformats).

  6. #6
    Join Date
    Jan 2006
    Posts
    368
    Thanks
    14
    Thanked 18 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default 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

  7. #7
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    258
    Thanks
    22
    Thanked 19 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: RightToLeft QTextEdit for Hebrew

    Quote Originally Posted by mchara View Post
    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:
    right-to-left2.jpg
    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:
    Qt Code:
    1. #include <QtGui>
    2. class MainWindow : public QMainWindow
    3. {
    4. Q_OBJECT
    5. public:
    6. MainWindow(QWidget* parent = 0) : QMainWindow(parent) {
    7. QWidget* cw = new QWidget;
    8. lo->addWidget(new QLineEdit);
    9. lo->addWidget(new QTextEdit);
    10. cw->setLayout(lo);
    11. setCentralWidget(cw);
    12. }
    13. };
    14.  
    15. int main(int argc, char** argv)
    16. {
    17. QApplication app(argc, argv);
    18. app.setLayoutDirection(Qt::RightToLeft);
    19. MainWindow mw;
    20. mw.show();
    21. return app.exec();
    22. }
    23. #include "main.moc"
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. QTextEdit slow to insert text
    By thomaspu in forum Qt Programming
    Replies: 4
    Last Post: 10th January 2008, 12:05
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.