Qt踩坑第五天(界面布局和样式表)

在Qt中主要提供的是Layout类及其子类来布局管理器。它们可以实现常用的布局管理功能。
而布局管理可以用两个字来归纳:排版
布局方式:
Vertical Layout
Horizontal Layout
Grid Layout
From Layout
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
布局器的边框
Layout也有它的属性配置。
在这里插入图片描述
样式表

void setStyleSheet(QString sheetName)
{
//设置样式表
QFile file("../css/" + sheetName + ".css");
file.open(QFile::ReadOnly);
QString styleSheet=QString::fromLatin1(file.readAll());
qApp->seStyleSheet(styleSheet);
}

1、布局管理器
1.1认识布局
在这里插入图片描述
布局管理器只有在编辑时才能被看到。
布局管理器可以对布局本身进行布局。
也可以是使用弹簧来占位,不想布局可以使用“打破布局”
1.2布局策略
控件在布局管理器中的“摆放策略”;
在Qt助手中搜索QSizePolicy;展示策略。
在这里插入图片描述
在这里插入图片描述
选中一个PushButton,策略默认为Minimum,Fixed,0,0比如现在把水平改为Fixed垂直改为Wxpanding
在这里插入图片描述
重点理解:
Expanding---------把两边撑满
Preferred-----------最优的
2、样式表
2.1参考文档及Demo
2.2定制PushButton

QPushButton { /* QPushButton{} 表示{}的qss对真个button生效  */        
border: 2px solid #8f8f91; /* 边框<两个像素 实线 颜色> */       
 border‐radius: 6px; /* 圆角 6个像素  */
background‐color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
 /* 背景 渐变颜色 */
 stop: 0 #f6f7fa, stop: 1
#dadbde);
        min‐width: 80px; /* 最小宽度 80像素 */   }

  QPushButton:pressed { /* 鼠标按下去的效果 */
background‐color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1,
stop: 0 #dadbde, stop: 1
#f6f7fa);
   }

QPushButton:flat {
border: none; /* no border for a flat push button */ }

QPushButton:default {
border‐color: navy; /* make the default button prominent */     }

在这里插入图片描述
无边框的button

QPushButton{
border:none;/* no border for a flat push button */
}

无边框的情况上颜色

QPushButton{
border:none;
background-color:rgb(255,52,26);
}

鼠标经过时上颜色

QPushButton
{
border:none;
background-color:rgb(255,52,26);
}
QPushButton::hover
{
background-color:rgb(255,151,76);
}

能够使用UI工具添加尽量不用代码添加,鼠标点下去在进行上色
QPushButton{
boder:none;
background-color:rgb(255,52,26);
}
QPushButton::hover
{
background-color:rgb(255,151,76);
}
QPushButton:pressed
{
background-color:rgb(235, 255, 105);
}

右上角整成圆角

QPushButton {
border: none; /* no border for a flat push button */
background‐color: rgb(255, 52, 26);
border‐top‐right‐radius:5px; /* 上右 5个像素圆角  */
}
QPushButton::hover { background‐color: rgb(255, 151, 76);
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值