QTextedit设置锚点并滚动到它 [英] QTextedit set anchor and scroll to it

查看:1532
本文介绍了QTextedit设置锚点并滚动到它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在 QTextEdit 中设置锚点?

似乎有一种方法可以滚动到

There seems to be a method to scroll to an anchor, but not any method to set actually one.

所以我试过这个,但它不工作。

So I tried this, but it does not work.

mTextEdit->setHtml("some html stuff");
mTextEdit->append("<a href=\"#word\">word</a>");
mTextEdit->scrollToAnchor("word");

有任何建议吗?

推荐答案

您必须向锚点提供名称属性,如下所示:

You have to give the name attribute to your anchor , like this:

mTextEdit->append("<a name=\"scrollToMe\" href=\"#word\">word</a>");

然后调用scrollToAnchor函数:

and then call the scrollToAnchor function:

mTextEdit->scrollToAnchor("scrollToMe");

这篇关于QTextedit设置锚点并滚动到它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆