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. QTextEdit - how to capture the actual "selection changed " text ?
Forum Updated to NodeBB v4.3 + New Features

QTextEdit - how to capture the actual "selection changed " text ?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 1.2k 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    Am I using wrong widget ?

    I am using "system" call to fill QTextEdit.
    Then I need to select and process specific text.
    Putting a mouse on ANY part of the desired text generates
    "selection changed" signal, works fine...

    How do I retrieve the actual text ?

    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      Am I using wrong widget ?

      I am using "system" call to fill QTextEdit.
      Then I need to select and process specific text.
      Putting a mouse on ANY part of the desired text generates
      "selection changed" signal, works fine...

      How do I retrieve the actual text ?

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

      @AnneRanch
      The whole of the text is available through textEdit->toPlainText().
      The selected text is available through textEdit->textCursor().selectedText() or textEdit->textCursor().selection().toPlainText().

      Separately.
      Presumably you had to write or find some code to capture the output from a system() call to get it into a QTextEdit. And it involved doing something with stdout. The Qt way of doing this can be reduced to (no error checking):

      QProcess process;
      process.start("/bin/ls", QStringList() << "-la");    // example for: system("/bin/ls -la")
      process.waitForFinished();
      textEdit->setPlainText(process.readAllStandardOutput());
      
      1 Reply Last reply
      2
      • A Offline
        A Offline
        Anonymous_Banned275
        wrote on last edited by
        #3

        This does not work - no data retrieved.
        QString textSelection = ui->textEdit_6->textCursor().selectedText();

        This works fine , BUT I do not need ALL text, just selected one.

        textSelection = ui->textEdit_6->toPlainText();
        
        JonBJ 1 Reply Last reply
        0
        • A Anonymous_Banned275

          This does not work - no data retrieved.
          QString textSelection = ui->textEdit_6->textCursor().selectedText();

          This works fine , BUT I do not need ALL text, just selected one.

          textSelection = ui->textEdit_6->toPlainText();
          
          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @AnneRanch said in QTextEdit - how to capture the actual "selection changed " text ?:

          QString textSelection = ui->textEdit_6->textCursor().selectedText();

          It should do, assuming text has been selected there, like dragging the mouse over it so that you see the selected text highlighted. You can try the alternative ui->textEdit_6->textCursor().selection().toPlainText() though it should return the same result.

          A 1 Reply Last reply
          0
          • JonBJ JonB

            @AnneRanch said in QTextEdit - how to capture the actual "selection changed " text ?:

            QString textSelection = ui->textEdit_6->textCursor().selectedText();

            It should do, assuming text has been selected there, like dragging the mouse over it so that you see the selected text highlighted. You can try the alternative ui->textEdit_6->textCursor().selection().toPlainText() though it should return the same result.

            A Offline
            A Offline
            Anonymous_Banned275
            wrote on last edited by
            #5

            @JonB I still think I am using wrong widget / signal. I can only position and click the mouse. I cannot highlight the text - the positioning of mouse overrides that.

            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