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 find the visible part

QTextEdit : How to find the visible part

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

    The problem is how to find out exactly which part of the QTextEdit is currently visible, meaning starting with the first block#/line#/character# that is visible and ending with the last block#/line#/character# that is still visible.

    A solution that returns the positions of these characters inside the QTextEdit is good enough, as these can be converted to block#/line#/character#.

    I have seen one very partial solution (here) that involved arithmetic between the viewport and the bounding rectangles of blocks. But beside its complexity, it only finds block-numbers.

    Can anybody answer this question?

    1 Reply Last reply
    0
    • H Offline
      H Offline
      Harry123
      wrote on last edited by Harry123
      #2

      Finally it's up to me to answer my question.

      One can use QTextEdit::cursorForPosition that uses viewport coordinates

      QTextEdit textEdit;
      int start_pos = textEdit.cursorForPosition(QPoint(0, 0)).position();
      QPoint bottom_right(textEdit.viewport()->width() - 1, textEdit.viewport()->height() - 1);
      int end_pos = textEdit.cursorForPosition(bottom_right).position();
      
      1 Reply Last reply
      3
      • S Offline
        S Offline
        sanjay1155
        wrote on last edited by
        #3
        This post is deleted!
        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