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 create gaps and highlight text blocks?
Forum Updated to NodeBB v4.3 + New Features

QPlainTextEdit: how create gaps and highlight text blocks?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 1 Posters 1.5k 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.
  • A Offline
    A Offline
    AndrzejB
    wrote on 10 Feb 2018, 01:56 last edited by
    #1

    I am planning create visual diff tool like WInMerge. Two panels, there editors from example "CodeEditor". It Is possible make line numbers with gaps because coder has full control on line numbers. But how highlight many blocks of text? How deny edit on "gaps"? (another question is syntax highlight but it can be later)

    1 Reply Last reply
    0
    • A Offline
      A Offline
      AndrzejB
      wrote on 10 Feb 2018, 02:45 last edited by
      #2

      Highligting, QTextEdit:

          int begin = editor->document()->findBlockByNumber(5).position();
          int end = editor->document()->findBlockByNumber(10).position();
          QTextBlockFormat fmt;
          fmt.setProperty(QTextFormat::FullWidthSelection, true);
          fmt.setBackground(Qt::yellow);
      
          QTextCursor cursor(editor->document());
          cursor.setPosition(begin, QTextCursor::MoveAnchor);
          cursor.setPosition(end, QTextCursor::KeepAnchor);
          cursor.setBlockFormat(fmt);
      
      1 Reply Last reply
      3
      • A Offline
        A Offline
        AndrzejB
        wrote on 10 Feb 2018, 12:18 last edited by AndrzejB 2 Oct 2018, 16:52
        #3

        One warning: this correct makes one highlighted block, but is bad if I want create many blocks. mergeBlockFormat not helps. Maybe can I use QSyntaxHighlighter for it?

        Is unsolved: MoveAnchor/KeepAnchor not let me multiple blocks, worse - I can't restore default block type.

                QTextCursor cursor(editor->document());
                cursor.setPosition(begin, QTextCursor::MoveAnchor);
                cursor.setPosition(end, QTextCursor::KeepAnchor);
                cursor.setBlockFormat(fmt);
        
                QTextBlockFormat fmtNormal;
                cursor.setPosition(begin, QTextCursor::MoveAnchor);
                cursor.setPosition(end, QTextCursor::KeepAnchor);
                cursor.setBlockFormat(fmtNormal);
        

        This cut me document
        I need:

                QTextBlock block = editor->document()->findBlockByLineNumber(begin);
                block.setBlockFormat(fmtNormal); <---this not  compiles
        
        1 Reply Last reply
        0

        1/3

        10 Feb 2018, 01:56

        • Login

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