Layout是一种各种UI都很长用的布局手段,Qt的就很不错,比如说GridLayout,你可以把整个窗体布局一个GridLayout,
然后再往GridLayout里面放控件或者其他布局,这种布局的手段可以随窗体变化而改变布局内的控件的大小,而相对的位置不变。
使用布局时,在复杂的情况下,需要结合很多的手段才可以达到理想的效果,而且一般使用手写代码更为方便。
有几个因素供参考:
1大小提示(size hint)和最小大小提示(minimum size hint)
2大小策略(size policy)
3伸缩因子(stretch factor)
4大小约束(size constraint)
5空白(margin)和间距(spacing)
还有,对于布局而言,对于一个窗口,要达到你说的那个基本目标,首要的就是要设置顶级布局(Top Level Layout)。比
如用designer时要注意, 要点中外层的widget然后选layout, 而不是选中若干子控件再选layout, 因为后者的layout和外
层的widget没有建立起联系, 这样就不会随着widget的大小改变而改变了。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;
background-image: url(:/images/pagefoldpng);
background-position: top right;
background-repeat: no-repeat
}
把上面的改成:
QMainWindow > QWidget {
background-color: gainsboro;
border-image: url(:/images/pagefoldpng);
}
就能实现你要的效果了,自动将pagefoldpng拉伸填满整个背景。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)