簡體   English   中英

如何設置Qt工具提示寬度

[英]How to set Qt tooltip width

需要在工具提示中顯示帶有粗體和多色字符的2行文本,但似乎工具提示具有最大寬度並且文本被剪切。 我試圖計算文本的寬度並手動設置寬度,但它沒有產生任何效果,似乎style =“width:some px”不適用於工具提示。 這是代碼:

編輯

QString tooltip = "<div style= \"white-space: nowrap; width: 1500px;\">Some text for tooltip, which is too long</div>";

對工具提示沒有影響

如何更改工具提示寬度?

使用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));

這有點清潔......
另外,不要設置“white-space:nowrap;”,這樣做的寬度很小會切斷文本
並且,如果可能的話,不要硬編碼類名,因為沒有__CLASS__我使用__FUNCTION__

如果你真的想要Qt Linguist的類名(翻譯函數),請確保打開RTTI編譯器選項並使用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
                                 ));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM