1

I can get the line number of a cursor in a QTextEdit. but can't achieve to get the column number information. (Note: I use QTextBlock while getting line number info.) Isn't there an easy way to obtain column number? What should i do? Although i read here and here, QTextBlock class is still confusing me.

Community
  • 1
  • 1
Barış Akkurt
  • 2,255
  • 3
  • 22
  • 37

1 Answers1

6

This is my solution to the problem:

QTextCursor cursor = ui.textEdit->textCursor();
int y = cursor.blockNumber() + 1;
int x = cursor.columnNumber() + 1;
Collin
  • 11,977
  • 2
  • 46
  • 60
user983302
  • 1,377
  • 3
  • 14
  • 23
  • Yes, that worked. Thanks (and shame on me for this easy question), but why the Qt people give a name such as blockNumber instead of line number and they insist using QTextBlock. – Barış Akkurt Oct 17 '12 at 20:44