Hi all!
I got a server problem about counting the line number in a text.~~
a mouse click a text,the position of cursor follow clicking to change a new place.How do I kown where it is.....I mean the line number???????many thanks!!!!!!!
Hi all!
I got a server problem about counting the line number in a text.~~
a mouse click a text,the position of cursor follow clicking to change a new place.How do I kown where it is.....I mean the line number???????many thanks!!!!!!!
Please read Qt4 documentation about the QTextCursor class.
As far as I know, there is no direct method to get the current line number. You might have to count it by yourself by iterating through the text blocks and comparing them to text cursors text block. Please someone correct me if I'm wrong! I hope I am, this isn't very convenient..
Qt Code:
int line = 0; { ++line; if (block == cursor) break; } qDebug() << "line" << line;To copy to clipboard, switch view to plain text mode
This might become a little costly if it's calculated all the time when cursor moves...
It might be worth taking a quick look at this article:
Lazy updating for ascertaining block numbers in a document
J-P Nurmi
Alina (23rd August 2006)
Bookmarks