3

Given a text block, is there a way to determine its offset relative to the coordinates (0, 0) of the current document layout?

For example, suppose I have a QPlainTextEdit with the following contents:

Line 1
Line 2

If the height of each line is 17px, how can I get the offset of line 2? Since line 1 is at the top, it should be 0px from the top and line 2 should be 17px from the top.

I tried a number of different functions but none of them seems to have the information:

None of these methods seem to work.

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361

1 Answers1

1

I believe you can try QTextCursor.

QTextEdit textEdit;
QTextCursor c =  textEdit->textCursor();
c.position();

or

c.positionInBlock();

Check documents on QTextCursor for details.

Bill
  • 190
  • 1
  • 8