How to round QToolTip corners with CSS and QT

2019-02-16 00:43发布

问题:

Please post some working example. The one below makes two borders: the rectangular background frame in black and a white outline with rounded edge. I can't believe it has not been done before.

app.setStyleSheet("QToolTip {
font-size:9pt;
color:white; padding:2px;
border-width:2px;
border-style:solid;
border-radius:20px;
background-color: black;
border: 1px solid white;}")

回答1:

The solution is to set a custom mask on tooltip widget. I can think of two ways of doing that:

  • Implement an own QStyle with a mask returned for QStyle::SH_ToolTip_Mask style hint. That is a generic way as default QToolTip would use this mask (example).

  • Create a custom QToolTip based class with a proper mask and then use QHelpEvent (QEvent::ToolTip) event of your widget to show it. It's not a generic solution as it requires to filter events on all widgets which need custom tooltip.