是否有比仅使用RegExp更好的方法来在QToolTip中自动换行? [英] Is there a better way to wordwrap text in QToolTip than just using RegExp?

查看:75
本文介绍了是否有比仅使用RegExp更好的方法来在QToolTip中自动换行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以问题在标题中.QToolTip似乎没有提供wordwraop功能.但是,可以使用正则表达式用\ n代替第N个空格,但是我想知道是否有人建议更好的解决方案.具体来说,我的方法存在的问题是它没有考虑文本的长度.例如,我希望较长的文本形成较宽的段落.

So the question is in the title. QToolTip doesn't seem to provide the wordwraop feature. It is possible, however, to replace the Nth space with an \n using regexps, but I was wondering if anyone has a suggestion for a better sollution. Specifically, my problem with my approach is that it doesn't take the length of text into account. For example I'd like longer texts to form wider paragraphs.

推荐答案

如果工具提示中的文本为富文本格式,则会自动将其自动换行.

If the text in a tooltip is rich text, it is automatically word-wrapped.

这是一个简单的示例,其中将字体设置为黑色会使它成为富文本",因此它会被自动换行.省略字体声明意味着工具提示将为纯文本,并扩展整个屏幕的长度.

Here's a trivial example, where setting the font to black makes it "rich text" and so it gets word wrapped. Leaving out the font declarations means the tooltip will be plain text and extend the whole length of the screen.

QString toolTip = QString("<FONT COLOR=black>");
toolTip += ("I am the very model of a modern major general, I've information vegetable animal and mineral, I know the kinges of England and I quote the fights historical from Marathon to Waterloo in order categorical...");
toolTip += QString("</FONT>");
widget->setToolTip(sToolTip);

当然,在此示例中,工具提示的宽度取决于平台.

Of course with this example, the width of the tooltip is up to the platform.

在Qt错误跟踪程序中,有一个关于此问题的新建议: https://bugreports.qt.io/browse/QTBUG-41051 .它还要求宽度是可变的.

There is a new suggestion in the Qt bug tracker about this problem: https://bugreports.qt.io/browse/QTBUG-41051. It also requests width to be changeable.

这篇关于是否有比仅使用RegExp更好的方法来在QToolTip中自动换行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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