qt的stylesheet中如何设置属性使背景图自动调整来适应控件的大小

A background-image does not scale with the size of the widget. To provide a "skin" or background that scales along with the widget size, one must use border-image. Since the border-image property provides an alternate background, it is not required to specify a background-image when border-image is specified. In the case, when both of them are specified, the border-image draws over the background-image.

默认background-image 不会缩放图片以适应控件的大小。
如果要提供一个皮肤或背景图片以自动适应控件大小,
必须也只能用border-image属性。
因为border-image已经设置了可用的背景图片,
所以使用了border-image后,没必要再指定background-image。
如果同时指定了两个属性,那么将会使用border-image 绘制覆盖掉background-image。
QMainWindow > .QWidget {
    background-color: gainsboro;
    border-image: url(:/images/pagefold.png);
}
自动将pagefold.png拉伸填满整个背景。

补:有时候同样的内容放在qss文件中不生效,但放在代码中就生效。

  • 11
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值