在 QTextEdit 中查找文本并将该行滚动到顶部

发布于 2024-09-26 01:10:40 字数 252 浏览 0 评论 0原文

有一个包含搜索关键字的 QListWidget 和一个包含一些文本的 QTextEdit。单击其中一个关键字应该会匹配 QTextEdit 中的单词并将相应的行滚动到顶部。

我使用信号/槽连接 QListWidget 和 QTextEdit 并执行 QTextEdit::find(),这几乎产生了所需的行为。但不幸的是,包含关键字的行没有滚动到顶部,而是位于 QTextEdit 的底部。我怎样才能轻松实现我的目标?

谢谢你的帮助,

克里斯

There is a QListWidget containing keywords for search and a QTextEdit containing some text. Clicking on one of the keywords should result in matching the word in the QTextEdit and scrolling the corresponding line to the top.

I connect the QListWidget and the QTextEdit with signal/slot and perform a QTextEdit::find(), which almost results in the desired behavior. But unfortunately the line containing the keyword is not scrolled to the top, rather it is on the bottom of the QTextEdit. How can I easily achieve my goal?

Thanks for your help,

Chris

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

分開簡單 2024-10-03 01:10:40

您可以尝试滚动到 QTextEdit 的末尾,然后进行搜索吗?这样它就会向上滚动到找到的单词。

Could you try scrolling to the end of the QTextEdit, then searching? That way it would scroll up to the found word.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文