我正在嘗試為 QRubberBand 設定工具提示。這就是父建構式的外觀。請注意,父級不是視窗,而是視窗的小部件。
roiRB = new QRubberBand( QRubberBand::Rectangle,this);
roiRB->setGeometry(QRect(QPoint(1,1), QPoint(100,100)));
roiRB->setAttribute(Qt::WA_AlwaysShowToolTips); //I tried this line as mentioned in the Documentation to all parent classes of the QRubberBand.
roiRB->setToolTip("Hello");
roiRB->setToolTipDuration(1000);
但是工具提示沒有彈出,我也為 toolTipDuration 嘗試了不同的值。
uj5u.com熱心網友回復:
如果您查看檔案,您可以閱讀:
請注意,默認情況下,工具提示僅針對作為活動視窗子級的小部件顯示。
Qt::WA_AlwaysShowToolTips
您可以通過在視窗上設定屬性來更改此行為,而不是在帶有 tooltip 的小部件上。
強調我的
您已經Qt::WA_AlwaysShowToolTips
使用工具提示在小部件上設定了屬性,而不是在視窗本身上設定了屬性,這與檔案中提到的完全相反。
uj5u.com熱心網友回復:
在挖掘 QRubberBand 的源代碼時,我發現在 QRubberBand 的建構式中,該屬性 (Qt::WA_TransparentForMouseEvents);
設定為 true。手動將其設定回 false 可解決此問題。
據我所知,工具提示適用于小部件的 MouseEvent 呼叫,如果此屬性設定為 true,則小部件將忽略 MouseEvents,從而使 setToolTip("abcd") 無效。
所以,
roiRB = new QRubberBand( QRubberBand::Rectangle,this);
roiRB->setAttribute(Qt::WA_TransparentForMouseEvents,0);
就是你需要做的。如果我錯過了什么,請告訴我。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/496981.html
標籤:C qt qt5 qrubberband
上一篇:Mac上的QTest::sendKeyEvent帶有真實(本機)Ctrl修飾符
下一篇:如何處理胖介面?