Box Model与控件样式

一、Box Model样式

1、当使用style sheets的时候,所有的控件都被当做是有4个同心矩形组成的方框模型。即:

  • margin rectangle :最外层的边框矩形
  • border rectangle :边界矩形
  • padding rectangle :填充边界矩形
  • content rectangle :显示内容的矩形

在这里插入图片描述
2、 marginborder-widthpadding默认值都是 0,所以默认情况下,这四个矩形是重叠的。
3、background-colorbackground-image等属性都是作用在 border rectangle 这个范围的矩形中的,margin rectangle 宽度的部分不包含在内。


二、不同方框模型使用

1、最外层的 margin rectangle

  1. 该属性可以指定 margin的宽度,可以默认一起指定,也可以单独指定。
    如:Btn01Btn02相同,指定Btn01margin宽度为20px。
  2. 此时等价于依次默认 margin-top,margin-right,margin-bottom,margin-left 都是20px的宽度。
ui.btn01->setStyleSheet("QPushButton#btn01 {background-color:rgba(0,200,200,0.8);margin:20px;}");

在这里插入图片描述

2、次外层的 border rectangle

  1. 常用的矩形方框就是border rectangle,其附带有更多的属性可以控制控件的UI。如:

    • border-width:控制border的宽度,若只默认设定一个值,则等价于按顺序border-top-widthborder-right-widthborder-bottom-widthborder-left-width都相等。也可以单独设定各个部分的宽度值。
    • border-style:设定控件边界宽度的样式
    • border-color:设置控件border部分宽度的颜色
    • border-radius:设置border-rectangle矩形的圆角半径,默认是四个圆角半径一样大小,可以单独设定每隔圆角大小。
    • border-image:设定空间的填充图片,此项用的最为广泛。因为该属性中的图片会随控件的拉伸而自动的拉伸进行填充。
  2. 应用示例,如设定QPushButton的一些对应border属性

ui.btn01->setStyleSheet("QPushButton#btn01 {background-color:rgba(0,200,200,0.8);border-width:20px;border-style:outset;border-radius:40px;border-color:blue;}");
ui.btn02->setStyleSheet("QPushButton#btn02 {background-color:rgba(0,200,200,0.8);border-width:10px;border-style:solid;border-radius:20px;border-color:red;}");

在这里插入图片描述

3、填充矩形padding rectangle

  1. 该属性可以指定填充的宽度,如指定的宽度太大的话,可能会留给content显示的控件就很少,导致内容只能显示出一部分。如当指定Btn01的对应padding很大时,其内容将会有一部分被遮挡。
  2. 分别设置不同位置的padding时,会导致content的大小发生变化。
ui.btn01->setStyleSheet("QPushButton#btn01 {background-color:rgba(0,200,200,0.8);padding:90px}");

ui.btn02->setStyleSheet("QPushButton#btn02 {background-color:rgba(0,200,200,0.8);padding-top:80px;padding-right:90px;}");

在这里插入图片描述

.x-form .x-btn{ height:25px; width:95px; line-height:25px; color:#000; background:#414143 url(images/btn_02.jpg); border:0px; margin-left:5px; } .x-form .x-brnull{ border-right:0px; } .x-msg{ background:#EEF5FF; margin:0px auto; color:#000; border:1px solid #ccc; } .x-msg A{ text-decoration:none; color:red; } .x-form .x-blnull{ border-left:0px; } .x-form-title,.x-form-title td{ font-weight:bold; color:#000; background:#eee; border:1px solid #dcdcdc; } .x-form-bBack td{ background:url(images/bg6.jpg) repeat-x; color:#FFF; border:1px solid #4D4D4D; } .x-form-bGreen td{ background:url(pic/bg14.jpg) repeat-x; } .x-form-title span,.x-form-title td span{ margin-left:10px; } /**列表***/ .x-list{ width:100%; font-size:12px; } /***列表Head**/ .x-list .x-head td,.x-list .x-head th{ /***background:url(images/head_bg.gif) repeat-x;**/ background:url(pic/bg14.jpg) repeat-x; height:27px; line-height:27px; text-align:center; font-weight:bold; } /**行的默认颜色**/ .x-list td{ padding-left:3px; height:27px; line-height:27px; border:1px solid #dcdcdc; } .x-list .x-sRow td{ background:#F8F8F8; } /**偶数行背景颜色***/ .x-list .x-dRow td{ background: #FBECC6; } /**选中TD背景颜色**/ .x-list .x-stRow td{ background:#d5effc url(images/td_over.png) repeat-x; } /**内容显示位置 left center right**/ .x-list .x-l{ text-align:left; } .x-list .x-c{ text-align:center; } .x-list .x-l{ text-align:right; } /**分页**/ .x-list .x-page{ height:35px; line-height:35px; background:#eee; text-align:center; } .x-list .x-page A{ margin-left:5px; text-decoration:none; color:#004A9B; } .x-list .x-page A:hover{ color:#404040; } .x-list td .x-a A{ text-decoration:none; color:#000; } .x-list td .x-a A:hover{ text-decoration:underline; color:#999; } 比较实用的box样式表单
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值