向widget中加背景图片和tooltip时,发现tooltip气泡的背景也改变了。
发现是border-image这里的问题
widget->setToolTip(name);//气泡
widget->setStyleSheet("border-image:url("+filePath+")"); //插入图片路径
因为border是适应控件大小插图的,这样做的可能不美观,看不出动态效果,甚至影响tooltip背景。
改成background-image
widget->setToolTip(name);//气泡
widget->setStyleSheet("background-image:url("+filePath+")");//图片路径
在qss中设置一下图片大小控件大小,加个动态效果
QFrame#titleFrameRight QWidget
{
background-repeat: no-repeat;
background-position:center;
width: 24px; //widget大小
height: 24px;
background-color: transparent;
background-size:16px 16px; //图片大小
border:none;
}
QFrame#titleFrameRight QWidget:hover
{
background-repeat: no-repeat;
background-position:center;
width: 24px;
height: 24px;
background-color: rgba(198, 206, 214, 0.2);
background-size:16px 16px;
border:none;
}
QFrame#titleFrameRight QWidget:pressed
{
background-repeat: no-repeat;
background-position:center;
width: 24px;
height: 24px;
background-color: rgba(198, 206, 214, 0.4);
background-size:16px 16px;
border:none;
}
最后