Qt学习四-QPushButton按钮用法二

目录

1.按钮头文件

2.QPushButton常用用法

3.setStyleSheet详解

3.1.border

3.2.border-image

3.3.background-image

3.4.font

3.5.color

4.setStyleSheet总结


1.按钮头文件

#include <QPushButton>  //调用按钮头文件

2.QPushButton常用用法

方法功能
setFixedSize(w,h)设置控件窗口大小
setMinimumSize(w,h)在使用setFixedSize后仍然可用来设置窗体的最小值
setMaximumSize(w,h)在使用setFixedSize后仍然可用来设置窗体的最大值
setGeometry(x,y,l,w)在屏幕上(x,y)的地方显示一个l*w的界面,但受layout布局限制,只能在父控件的范围内调整位置,在使用了此函数后一定要调用show函数,否则可能看不到控件
setDefault(bool)设置默认选中按钮(回车时有效)

3.setStyleSheet详解

3.1.border

pushbutton->setStyleSheet("QPushButton{border:1px solid red;...}");    //基本样式
pushbutton->setStyleSheet("QPushButton{border:%1...}").arg(border);    //外部调用时

a.border设置的是四个边框的宽度、样式和颜色

border:border-width border-style border-color;

border-width

1.可以是thin,medium,thick

2.也可以用长度单位定值,可以用绝对长度单位(cm, mm, in, pt, pc)或者相对长度单位 (em, ex, px)。

border-style

none: 无样式;
hidden: 同样是无样式,主要用于解决和表格的边框冲突;
dotted: 点划线;
dashed: 虚线;
solid: 实线;
double: 双线,两条线加上中间的空白等于border-width的取值;
groove: 槽状;
ridge: 脊状,和groove相反;
inset: 凹陷;
outset:凸出,和inset相反;

b.单边边框的设置方法

border-top:border-width border-style border-color;         //三种属性一起设置

//三种属性分开设置

 {
border-top-width:1px;
border-top-style:solid;
border-top-color:#FF0000;
}

//也可以

{ border-top:1px solid #FF0000; }

border-right        //右边框属性

border-bottom        //下边框属性

border-left        //左边框属性

c.border-style设置元素所有边框的样式,或者单独地为各边设置边框样式

border-style:solid solid solid solid;        //上 右 下 左

当是none时隐藏边框

3.2.border-image

pushbutton->setStyleSheet("QPushButton{border-image:url(:/路径);...}");    //基本样式
pushbutton->setStyleSheet("QPushButton{border-image:url(%1)...}").arg(border-image);    //外部调用时

 使用了border-image之后,即使设置了border也没有任何边框作用。

注:使用border-image:url(%1)和border:%1的格式,没有url时使用括号会不显示设置后的样式

3.3.background-image

pushbutton->setStyleSheet("QPushButton{background-image:url(:/路径);...}");    //基本样式
pushbutton->setStyleSheet("QPushButton{background-image:url(%1)...}").arg(border-image);    //外部调用时

background-repeat:no-repeat        //不重复

background-position:center        //在中心位置显示

3.4.font

pushbutton->setStyleSheet("QPushButton{font:14px bold "微软雅黑";...}");    //基本样式
pushbutton->setStyleSheet("QPushButton{font:%1...}").arg(font);    //外部调用时

3.5.color

参考网址:

4.setStyleSheet总结

样式-英文参数样式-中文
colorwhite/rgb(110,110,100)/#eb7350字体颜色
backgroundtransparent背景为透明
background-colorwhite/rgb(110,110,110)/#eb7350背景颜色
background-positionleft/right/center/top/bottom设定图片的位置
background-image:url()./img/back.png背景图片,不会缩放图片大小
background-repeatno-repeat不重复填充图片
border-image:url()./img/back.png背景图片,会对图片进行拉伸,平铺
border-styleoutset/inset边框样式,按下是inset
border-widthpx边框大小
border-radiuspx边框弧度
border3px solid red边框宽度及颜色
border-colorrgba(255,255,255,0)边框颜色,0时透明
font-family微软雅黑设定字体
fontbold 14px字体大小并加粗
font-sizepx字体大小
font-styleinset字体样式
font-weightpx字体深浅
selection-colorcolor设定选中时候的颜色
  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值