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. Proper selection from QPlainTextEdit
Qt 6.11 is out! See what's new in the release blog

Proper selection from QPlainTextEdit

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 1.5k 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.
  • Y Offline
    Y Offline
    YAPPO
    wrote on last edited by
    #1

    Hi everyone.
    Let's see on the next example of QPlaintTextEdit containing
    @
    text_text
    text_text place_1/place_2/place_3 text_text
    text
    @

    I need to get string "place_1/place_2/place_3" and set it to some QString variable by placing cursor on this very string (by clicking on this part of text or by changing cursor position by arrows). A tried several ways to do it but they didn't help. I can use TextCursor::WordUnderCursor selection but symbol '/' is a split symbol what means I can't select this entire string with this option. Another option is to get an entire line from text browser and somehow determine position of considering part in this somehow. The other option is to use QTextBlockFormat but I can't understand what is a block of text by default (lines, some number of chars, etc) and how I can change the policy of splitting text on blocks.

    I think this problem is quite common and there should be an easy way to solve it. Can anyone help?

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Code_ReaQtor
      wrote on last edited by
      #2

      Why not store all the text into a QString then apply QRegExp into it to get the specific string that you needed? Do you actually need to select it by cursor?

      Please visit my open-source projects at https://github.com/Code-ReaQtor.

      1 Reply Last reply
      0
      • Y Offline
        Y Offline
        YAPPO
        wrote on last edited by
        #3

        [quote author="Code_ReaQtor" date="1364997077"]Why not store all the text into a QString then apply QRegExp into it to get the specific string that you needed? Do you actually need to select it by cursor?[/quote]

        Yes, I really need to select it by cursor because my task is to make some kind of completer and I have to be sure what part of the text I'm working with. If the text in QPlainTextEdit is split onto blocks by new_lines ('\n') then I can take all the line (because it is a block) and then fetch considering part of the line by using positionInBlock().

        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