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. QTextCursor::setPosition() not working in my QTextEdit.
Forum Updated to NodeBB v4.3 + New Features

QTextCursor::setPosition() not working in my QTextEdit.

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 3 Posters 2.2k 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.
  • D Offline
    D Offline
    dokif
    wrote on last edited by
    #1

    Hi, I cannot manage to move textCursor of QTextEdit with setPosition function.
    The following instruction does not work in my Qt 5.10.0:

    this->textCursor().setPosition(0);
    

    Nothing happens. I want to move cursor to specific position in the text already written, thats why i'm not using movePosition function.

    Thanks.

    1 Reply Last reply
    0
    • Christian EhrlicherC Online
      Christian EhrlicherC Online
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by
      #2

      You need to set the cursor with setTextCursor(). textCursor only returns the current QTextCursor. See documentation: http://doc.qt.io/qt-5/qtextedit.html#textCursor

      "Returns a copy of the QTextCursor that represents the currently visible cursor. Note that changes on the returned cursor do not affect QTextEdit's cursor; use setTextCursor() to update the visible cursor."

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      1 Reply Last reply
      3
      • Jimmy CrabJ Offline
        Jimmy CrabJ Offline
        Jimmy Crab
        wrote on last edited by
        #3

        Thanks Christian.
        So the code is like this:

         tbx->setFocus();
         QTextCursor cursor = tbx->textCursor();
         cursor.setPosition(5);
         tbx->setTextCursor(cursor);
        

        Just do it.

        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