向widget中加背景图片和tooltip时,tooltip气泡的背景也改变的问题

9 篇文章 0 订阅

向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;
}

最后

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值