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. move QTextCursor

move QTextCursor

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 483 Views
  • 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.
  • M Offline
    M Offline
    Martinuccia_96
    wrote on last edited by
    #1

    Hi, everyone.
    I'm trying to move a QTextCursor in a specific position. I'm trying with the following code, but i'm not obtaining results:

        QTextCursor curs=ui->textEdit->textCursor();
        curs.movePosition(QTextCursor::Start);
        ui->textEdit->setTextCursor(curs);
    

    With this solution, the cursor simply disappears from my textEdit.
    Can you help me?

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

      Hi,

      What version of Qt ?
      On what OS ?
      Please provide a minimal compilable example that reproduce this behaviour.

      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
      1
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by mrjj
        #3

        Hi
        QDebug is your friend :)

           QTextCursor curs = ui->textEdit->textCursor();
            qDebug() << "now:" << curs.position();
            curs.movePosition(QTextCursor::Start);
            ui->textEdit->setTextCursor(curs);
            qDebug() << "after:" << curs.position();
        

        It goes to position 0

        The cursor is not vanishing by an error. ( i'm guessing here..)
        I think you use a button or something like that to test the code.
        Then the button will then take focus (when you click it) and hence the cursor is not shown since
        the TextEdit no longer has focus. the button has.

        set button to NoFocus and see.
        alt text

        alt text

        M 1 Reply Last reply
        1
        • mrjjM mrjj

          Hi
          QDebug is your friend :)

             QTextCursor curs = ui->textEdit->textCursor();
              qDebug() << "now:" << curs.position();
              curs.movePosition(QTextCursor::Start);
              ui->textEdit->setTextCursor(curs);
              qDebug() << "after:" << curs.position();
          

          It goes to position 0

          The cursor is not vanishing by an error. ( i'm guessing here..)
          I think you use a button or something like that to test the code.
          Then the button will then take focus (when you click it) and hence the cursor is not shown since
          the TextEdit no longer has focus. the button has.

          set button to NoFocus and see.
          alt text

          alt text

          M Offline
          M Offline
          Martinuccia_96
          wrote on last edited by
          #4

          @mrjj Thanks so much

          mrjjM 1 Reply Last reply
          0
          • M Martinuccia_96

            @mrjj Thanks so much

            mrjjM Offline
            mrjjM Offline
            mrjj
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @Martinuccia_96
            Well it also fooled me for a moment :)
            Then i recalled that buttons takes focus too so they can activate with keyboard.

            1 Reply Last reply
            0

            • Login

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