Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Wrong cursor shape in QTextEdit with non-ascii
Forum Updated to NodeBB v4.3 + New Features

Wrong cursor shape in QTextEdit with non-ascii

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 3 Posters 884 Views 3 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • Y Offline
    Y Offline
    Yves Judd
    wrote on last edited by
    #1

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

    0_1538023594817_correct.png
    1_1538023594818_wrong.png

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

    Can anybody help me ?

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi and welcome to devnet,

      How do you insert that in your QTextEdit ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      Y 1 Reply Last reply
      0
      • Y Offline
        Y Offline
        Yves Judd
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • SGaistS SGaist

          Hi and welcome to devnet,

          How do you insert that in your QTextEdit ?

          Y Offline
          Y Offline
          Yves Judd
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

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

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            0
            • P Offline
              P Offline
              PeAlbe
              wrote on last edited by
              #6

              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;
                              default:
                                  break;
                              }
                          }
                      }
                      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.

              1 Reply Last reply
              0
              • SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                2

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved