Important: Please read the Qt Code of Conduct -

Wrong cursor shape in QTextEdit with non-ascii

  • I'm using Qt 5.11 with QTextEdit on Windows, the cursor shape (vertical line) look like flag if it contains non-ascii.


    #include <QApplication>
    #include <QTextEdit>
    int main(int argc, char *argv[])
        QApplication a(argc, argv);
        QTextEdit textedit;;
        return a.exec();

    Can anybody help me ?

  • Lifetime Qt Champion

    Hi and welcome to devnet,

    How do you insert that in your QTextEdit ?

  • This post is deleted!

  • @SGaist Input from keyboard or call QTextEdit::setText I got same result.

  • Lifetime Qt Champion

    Can you post a text sample that can be used to reproduce this ?

  • If you look inside QTextLayout::drawCursor, which actually paints the text cursor, you will see something like:

    if (d->layoutData->hasBidi) {
            const int arrow_extent = 4;
            int sign = rightToLeft ? -1 : 1;
            p->drawLine(QLineF(x, y, x + (sign * arrow_extent/2), y + arrow_extent/2));
            p->drawLine(QLineF(x, y+arrow_extent, x + (sign * arrow_extent/2), y + arrow_extent/2));

    that flag can be set to true by the function checkForBidi() inside qtextengine.cpp, which does the following:

        bool checkForBidi() const
            if (baseLevel != 0)
                return true;
            for (int i = 0; i < length; ++i) {
                if (text[i].unicode() >= 0x590) {
                    switch (text[i].direction()) {
                    case QChar::DirR: case QChar::DirAN:
                    case QChar::DirLRE: case QChar::DirLRO: case QChar::DirAL:
                    case QChar::DirRLE: case QChar::DirRLO: case QChar::DirPDF:
                    case QChar::DirLRI: case QChar::DirRLI: case QChar::DirFSI: case QChar::DirPDI:
                        return true;
            return false;

    I would like to avoid recompiling Qt libraries for a small thing like this, yet I find that arrow-thing on the cursor annoying, especially if you set the cursor width to 0 to make it invisible.

  • Lifetime Qt Champion

    It's not a "non-ascii" thing. It's when you have text containing chars that makes it bidirectional. However, it might be a good idea to raise the question about drawing that triangle when the cursor with is 0. You should check the bug report system to see if there's already something related.

Log in to reply