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. Append text on where cursor pointed | QPlainText
Forum Updated to NodeBB v4.3 + New Features

Append text on where cursor pointed | QPlainText

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 4 Posters 437 Views 1 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.
  • E Offline
    E Offline
    ELEMENTICY
    wrote on last edited by
    #1

    Hello,can i ask how do i append the text where the text pointer pointed?

    Like in normal code editor,when u press tab it append 4 space

    this is my code:

    void keyPressEvent (QKeyEvent * event) {
        if(event->key() == Qt::Key_Tab ) {
            
        }
    }
    

    what to do to add 4 space to where the text pointer pointed

    please help

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

      Imo not possible with QPlainTextEdit - you have to use QTextEdit

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

      E JonBJ 2 Replies Last reply
      0
      • Christian EhrlicherC Christian Ehrlicher

        Imo not possible with QPlainTextEdit - you have to use QTextEdit

        E Offline
        E Offline
        ELEMENTICY
        wrote on last edited by
        #3

        @Christian-Ehrlicher But i need to use plaintext,cuz i alr set much thing for it.Any other way to do that?

        1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          Imo not possible with QPlainTextEdit - you have to use QTextEdit

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

          @Christian-Ehrlicher

          Imo not possible with QPlainTextEdit - you have to use QTextEdit

          Why do you say this? You know better than I, but from https://doc.qt.io/qt-5/qplaintextedit.html#using-qplaintextedit-as-an-editor

          Selection of text is handled by the QTextCursor class, which provides functionality for creating selections, retrieving the text contents or deleting selections. You can retrieve the object that corresponds with the user-visible cursor using the textCursor() method.

          Isn't that what @ELEMENTICY needs?

          Christian EhrlicherC 1 Reply Last reply
          0
          • JonBJ JonB

            @Christian-Ehrlicher

            Imo not possible with QPlainTextEdit - you have to use QTextEdit

            Why do you say this? You know better than I, but from https://doc.qt.io/qt-5/qplaintextedit.html#using-qplaintextedit-as-an-editor

            Selection of text is handled by the QTextCursor class, which provides functionality for creating selections, retrieving the text contents or deleting selections. You can retrieve the object that corresponds with the user-visible cursor using the textCursor() method.

            Isn't that what @ELEMENTICY needs?

            Christian EhrlicherC Online
            Christian EhrlicherC Online
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #5

            @JonB You're right - I was under the impression that QPlainTextEdit killed this in favor of speed. But it's not the case.

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

              Hi
              I think you can just do
              ui->plainTextEdit->insertPlainText ("\t\t\t\tTEXT");

              1 Reply Last reply
              1

              • Login

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