Q. How to find row number(current line) from QTextEdit?
Description of problem:
Enter one line, now again enter second line so that it should wrap in to third line. So, now if user will keep cursor at any place, it should give the row number of that particular line.
Solution:
int currentRowNumber()
{
QTextDocument * document = textEdit->document();
QTextBlock block = document ->begin();
QTextBlock currentBlock= textEdit->textCursor().block();
int row_number = 1;
while(block != currentBlock)
{
int num_char_blk = blk.length ();
double extraLine= double (num_char_blk )/double(textEdit->lineWrapColumnOrWidth());
row_number = row_number + ceil(extraLine);
block = block .next();
}
int pos_cur= textEdit->textCursor().position();
int pos_blk= blk2.position();
int diff_char = pos_cur- pos_blk;
if(diff_char>= textEdit->lineWrapColumnOrWidth())
{
double extraLine= double(diff_char)/double(editText->lineWrapColumnOrWidth());
row_number = row_number+ int(extraLine);
}
return row_number;
}
No comments:
Post a Comment