Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QTextEdit : how to force LeftToRight text direction for RightToLeft languages



  • I've tried, this:

    @
    QTextOption topt = textedit->document()->defaultTextOption();
    topt.setTextDirection(Qt::LeftToRight);
    textedit->document()->setDefaultTextOption(topt);
    @

    and this:

    @
    QTextCursor tc = textedit->textCursor();
    QTextBlockFormat tbf = tc.blockFormat();
    tbf.setLayoutDirection( Qt::LeftToRight );
    tc.setBlockFormat(tbf);
    textedit->setTextCursor(tc);
    @

    without success.

    Any ideas would be appreciated. (A QLineEdit would do just as well, but they don't seem to have as many options for controlling text direction.)

    (Why? The textedit will contain a regular expression including Arabic text. Pretty confusing to look at a regex where the text is reversed.)


Log in to reply