返回列表 发帖

计算qplainttextedit当前cursor的行号

  1.         //get the current line number
  2.         QTextCursor tc = edit->textCursor();
  3.         QTextLayout* lo = tc.block().layout();
  4.         //get the relative position in the block
  5.         int pos = tc.position() - tc.block().position();
  6.         int line = lo->lineForTextPosition(pos).lineNumber() + tc.block().firstLineNumber();
  7.         qWarning() << line;
复制代码

返回列表