需要显示2行文字的工具提示与粗体和多色字符,但似乎工具提示有最大的宽度和文本被切割。我试图计算文本的宽度并手动设置宽度,但是它没有产生任何效果,看起来样式=“宽度:一些px”对工具提示不起作用。下面是代码:
编辑的
QString tooltip = "<div style= \"white-space: nowrap; width: 1500px;\">Some text for tooltip, which is too long</div>";
如何更改工具提示宽度?
发布于 2013-06-20 11:29:16
使用QtCreator/Designer的属性部分,我使用:
<html>
<table width="25">
<tr>
<td width="25">alwkefjwekf</td>
</tr>
<tr>
<td width="25">a ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea e</td>
</tr>
</table>
</html>
这将帮助您了解如何更好地限制表的大小。我毫不怀疑,可能有更简洁的方式来表达这一点。
QtCreator生成的一个具体示例:
pushButton->setToolTip(QApplication::translate("MainWindow", " <html>\n"
" <table width=\"25\"><tr><td width=\"25\">alwkefjwekf</td></tr>\n"
" <tr><td width=\"25\">a ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea e</td></tr>\n"
" </table>\n"
" </html>", 0));
发布于 2014-10-09 07:57:03
这有点干净..。
此外,不要设置“空格:现在说了算”,这样做的小宽度将切断文本。
而且,如果可能的话,不要硬编码类名,因为没有__CLASS__,我使用了__FUNCTION__
如果您真的想要Qt语言学家的类名(翻译函数),请确保RTTI编译器选项是on的,并使用typeid(*this).name()
。
setToolTip( QApplication::translate(__FUNCTION__, " <html>\n"
" <div style=\"width: 300px;\">ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea ea</div>"
" </html>", 0
));
https://stackoverflow.com/questions/17221621
复制