计算qplainttextedit当前cursor的行号
- //get the current line number
- QTextCursor tc = edit->textCursor();
- QTextLayout* lo = tc.block().layout();
- //get the relative position in the block
- int pos = tc.position() - tc.block().position();
- int line = lo->lineForTextPosition(pos).lineNumber() + tc.block().firstLineNumber();
- qWarning() << line;
复制代码 |