如何设置Qt工具提示宽度

IKM*_*007 5 html css c++ qt tooltip

需要在工具提示中显示带有粗体和多色字符的2行文本,但似乎工具提示具有最大宽度并且文本被剪切.我试图计算文本的宽度并手动设置宽度,但它没有产生任何效果,似乎style ="width:some px"不适用于工具提示.这是代码:

编辑

QString tooltip = "<div style= \"white-space: nowrap; width: 1500px;\">Some text for tooltip, which is too long</div>";
Run Code Online (Sandbox Code Playgroud)

对工具提示没有影响

如何更改工具提示宽度?

Huy*_*Huy 3

使用 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>
Run Code Online (Sandbox Code Playgroud)

这应该可以帮助您了解如何更好地限制表的大小。我毫不怀疑可能有一种更简洁的方式来表达这一点。

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));
Run Code Online (Sandbox Code Playgroud)