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 396 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 30 Dec 2020, 06:37 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
    • C Offline
      C Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on 30 Dec 2020, 07:48 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 J 2 Replies Last reply 30 Dec 2020, 11:42
      0
      • C Christian Ehrlicher
        30 Dec 2020, 07:48

        Imo not possible with QPlainTextEdit - you have to use QTextEdit

        E Offline
        E Offline
        ELEMENTICY
        wrote on 30 Dec 2020, 11:42 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
        • C Christian Ehrlicher
          30 Dec 2020, 07:48

          Imo not possible with QPlainTextEdit - you have to use QTextEdit

          J Offline
          J Offline
          JonB
          wrote on 30 Dec 2020, 11:55 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?

          C 1 Reply Last reply 30 Dec 2020, 12:03
          0
          • J JonB
            30 Dec 2020, 11:55

            @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?

            C Offline
            C Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on 30 Dec 2020, 12:03 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
            • M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 30 Dec 2020, 12:12 last edited by
              #6

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

              1 Reply Last reply
              1

              1/6

              30 Dec 2020, 06:37

              • Login

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