Qt怎么獲取QTextEdit中文本的行數(shù)?blockcount()函數(shù)返回的只是段落數(shù)
4 回答

weixin_慕標(biāo)0144108
TA貢獻(xiàn)1條經(jīng)驗 獲得超0個贊
碰到了同樣的問題的, 看了別人的, 太草率了, 測試后, 布局知道 `~`
當(dāng)然這個要以場景區(qū)分, 這個應(yīng)該能解決你的問題了.
int ClassName::lineCount() const
{
? ? int c = 0;
? ? auto b = document()->begin();
? ? while (b.isValid() && b.layout()) {
? ? ? ? c += b.layout()->lineCount();
? ? ? ? b = b.next();
? ? }
? ? return c;
}

倚天杖
TA貢獻(xiàn)1828條經(jīng)驗 獲得超3個贊
QTextCursor tc = fileedit_window->textCursor(); //當(dāng)前光標(biāo)
int rowNum = tc.blockNumber() + 1;//獲取光標(biāo)所在行的行號

SMILET
TA貢獻(xiàn)1796條經(jīng)驗 獲得超4個贊
int QTextDocument::lineCount () const
這個就是你要的,和blockcount()的使用方法一樣。
- 4 回答
- 0 關(guān)注
- 5751 瀏覽
添加回答
舉報
0/150
提交
取消