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. QPlainTextEdit:How to cancel the display of line breaks at the end of a line when the cursor is selected?
Forum Updated to NodeBB v4.3 + New Features

QPlainTextEdit:How to cancel the display of line breaks at the end of a line when the cursor is selected?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 266 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.
  • zybzybZ Offline
    zybzybZ Offline
    zybzyb
    wrote last edited by
    #1

    By default, when the text is selected across lines, a small paragraph of line breaks will be displayed at the end, just like the green box marked in the picture.
    屏幕截图 2025-08-26 224111.png

    I 1 Reply Last reply
    0
    • zybzybZ zybzyb

      By default, when the text is selected across lines, a small paragraph of line breaks will be displayed at the end, just like the green box marked in the picture.
      屏幕截图 2025-08-26 224111.png

      I Offline
      I Offline
      IgKh
      wrote last edited by
      #2

      @zybzyb The screenshot is strange, normally the behavior of QPlainTextEdit when selecting multiple lines, is to extend the selection of all lines except the last up to the right edge of the viewport. Looks like you already tinkered some with it?

      Anyway, what implements it is buried deep inside the implementation of Qt's text layout subsystem, and it is not easy to override. Your easiest approach would be to override paintEvent and paint the background over that bit. You will need to use each QTextBlock's (of the backing QTextDocument) QTextLayout to obtain the tight content rectangle for each line, and paint over everything to the left of it.

      1 Reply Last reply
      3
      • zybzybZ Offline
        zybzybZ Offline
        zybzyb
        wrote last edited by
        #3

        I rewrote the paintEvent with reference to the source code of Qt, most of which are the same as the official source code, but before drawing with QTextLayout::d raw, the selection range was restricted, and the line breaks in the selection were removed, which can already fulfill my needs, thank you!

        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