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 position at any line and column
Forum Updated to NodeBB v4.3 + New Features

QTextCursor position at any line and column

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 421 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.
  • 0 Offline
    0 Offline
    04CH
    wrote on last edited by
    #1

    Hi, is there any posibility to move text cursor at any line and column in QTextEdit (even if it's empty)? As I understood cursor moves only relative to existing text in widget. Can I change this behavior?

    I need it for telnet response, which has ASCII ESC sequence. It tell's me position where i need to display next block of data.

    The only thing i can do now is insert \n character Y times and spaces X times to positioning text.

    Is this the only solution? Thanks.

    JonBJ 1 Reply Last reply
    0
    • 0 04CH

      Hi, is there any posibility to move text cursor at any line and column in QTextEdit (even if it's empty)? As I understood cursor moves only relative to existing text in widget. Can I change this behavior?

      I need it for telnet response, which has ASCII ESC sequence. It tell's me position where i need to display next block of data.

      The only thing i can do now is insert \n character Y times and spaces X times to positioning text.

      Is this the only solution? Thanks.

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @04CH
      Hello and welcome.

      I suspect that (inserting blank lines columns to reach a particular "position") probably is the only way to do it.

      QTextEdit has a backing document for its content (QTextEdit::document()). So if you think about it that would have no way of representing "there is some text at some arbitrary (row, column) position". As https://doc.qt.io/qt-6/qtextedit.html#details states:

      QTextEdit works on paragraphs and characters.

      If you really want to do a "terminal emulator" have a look at how e.g. QTermWidget does it. This maintains an array/list of lines with a fixed number of columns per line (as terminals like xterm do). It does not use anything like a QTextEdit. Rather it just uses a QWidget and QPainter::drawText() to write characters, so that they can appear wherever desired, see TerminalDisplay.cpp. This is very different from a QTextEdit/document approach. And btw as you can see a terminal emulator is really quite a lot of code!

      0 1 Reply Last reply
      3
      • JonBJ JonB

        @04CH
        Hello and welcome.

        I suspect that (inserting blank lines columns to reach a particular "position") probably is the only way to do it.

        QTextEdit has a backing document for its content (QTextEdit::document()). So if you think about it that would have no way of representing "there is some text at some arbitrary (row, column) position". As https://doc.qt.io/qt-6/qtextedit.html#details states:

        QTextEdit works on paragraphs and characters.

        If you really want to do a "terminal emulator" have a look at how e.g. QTermWidget does it. This maintains an array/list of lines with a fixed number of columns per line (as terminals like xterm do). It does not use anything like a QTextEdit. Rather it just uses a QWidget and QPainter::drawText() to write characters, so that they can appear wherever desired, see TerminalDisplay.cpp. This is very different from a QTextEdit/document approach. And btw as you can see a terminal emulator is really quite a lot of code!

        0 Offline
        0 Offline
        04CH
        wrote on last edited by
        #3

        @JonB Well, seems like i need to go a little deeper and write my own widget.
        Thank you very much for explanation and example links, appreciate 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