Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved move QTextCursor

    General and Desktop
    3
    5
    205
    Loading More Posts
    • 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
      Martinuccia_96 last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 1
        • mrjj
          mrjj Lifetime Qt Champion last edited by 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 1 Reply Last reply Reply Quote 1
          • M
            Martinuccia_96 @mrjj last edited by

            @mrjj Thanks so much

            mrjj 1 Reply Last reply Reply Quote 0
            • mrjj
              mrjj Lifetime Qt Champion @Martinuccia_96 last edited by

              @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 Reply Quote 0
              • First post
                Last post