在 Qt 控件中,有一个特殊的控件:当我们把鼠标放在 QLabel、QPushButton、QToolButton 等控件上面时,会出现提示语,这个提示语就是 QToolTip;想要出现提示语需要调用对应控件的 setToolTip() 方法。
下面我们对 QToolTip 进行样式更改
QToolTip {
font-family: "Microsoft YaHei";
font-size: 15px;
color: #BDC8E2;
font-style: italic;
font-weight: bold;
padding-left: 18px;
padding-right: 2px;
padding-top: 2px;
padding-bottom: 2px;
border-style: solid;
border-width: 1px;
border-color: aqua;
border-radius: 13px;
background-color: #2E3648;
background-image: url("./image1.png");
background-repeat: no-repeat;
background-position: left center;
}
效果图如下,上面的是按钮控件,下面的是当鼠标放上去时出现的 ToolTip 提示语
QToolTip 的设置理论上和 QLabel 保持一致,有兴趣的话可以参考我的另一篇博客 qss样式表之QLabel
但 QToolTip 无法做到背景透明,也无法改变形状,如果设置背景为 transparent 透明时,默认会添加黑色背景,如果设置圆角半径时,改变的只是内部的圆角半径,就像上面的例子一样!