ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

qt万能样式表模板

2022-01-09 11:06:40  阅读:379  来源: 互联网

标签:qt color background 边框 样式表 rgba border 模板 255


文章目录


在项目开发过程中,不可缺少的一部分就是界面的美化,软件做的怎么样,界面风格样式很重要。在qt中通过样式表,*.qss文件加载到程序中美化界面

一、效果

在这里插入图片描述
在这里插入图片描述

二、样式代码

代码如下:

QWidget
{
    color: rgb(255, 255, 255);  /*字体颜色*/
    background-color: rgb(3,21,106); /*背景色*/
}
/*按钮正常状态*/
QPushButton
{
    background-color:rgba(5,23,122);/*背景色*/
    min-height:30px; /*最小高度*/
    min-width:180px; /*最小宽度*/
    border-style:solid;/*边框样式 solid实线 none无边框 inset/outset 3D边框*/
    border-width:4px; /*边框宽度像素*/
    border-radius:10px;/*边框圆角半径像素*/
    border-color:rgba(43,60,139);/*边框颜色*/
    font-size:12pt;/*字体 字体大小*/
    color: rgb(255, 255, 255);/*字体颜色*/
    padding:6px; /*填衬*/
}
/*鼠标按下状态*/
QPushButton:pressed
{
    background-color:rgba(5,23,200);/*背景色*/
    border-color:rgba(43,60,139);/*边框颜色*/
    border-style:solid;/*边框样式 solid实线 none无边框 inset/outset 3D边框*/
    color: rgb(255, 255, 255);/*字体颜色*/
}
/*鼠标悬停状态*/
QPushButton:hover
{
    background-color:rgba(5,23,150);/*背景色*/
    border-color:rgba(43,60,239);/*边框颜色*/
    color: rgb(255, 255, 255);/*字体颜色*/
}
QLineEdit
{
    background-color:rgba(5,23,122);/*背景色*/
    min-height:30px; /*最小高度*/
    min-width:180px; /*最小宽度*/
    border-style:solid;/*边框样式 solid实线 none无边框 inset/outset 3D边框*/
    border-width:4px; /*边框宽度像素*/
    border-radius:10px;/*边框圆角半径像素*/
    border-color:rgba(43,60,139);/*边框颜色*/
    font-size:12pt;/*字体 字体大小*/
    color: rgb(255, 255, 255);/*字体颜色*/
    padding:6px;/*填衬*/
}
QComboBox
{
    background-color:rgba(5,23,122);
    color: rgb(255, 255, 255);/*字体颜色*/
    border-style:solid;/*边框样式 solid实线 none无边框 inset/outset 3D边框*/
    border-width:1px;/*边框宽度像素*/
    border-radius:4px;/*边框圆角半径像素*/
    border-color:rgba(43,60,139);/*边框颜色*/
    min-height:35px; /*最小高度*/
    font-size:12pt;
}
/*向下的三角形箭头样式*/
QComboBox::drop-down
{
     width:20px;
     border:none;
     background:transparent;
 }
/*向下的三角形箭头*/
QComboBox::down-arrow
{
    image:url(:/image/array_down.png);
}
/*下拉后的整个下拉窗体*/
QComboBox QAbstractItemView
{
background-color:rgba(5,23,150);
color: rgb(255, 255, 255);/*字体颜色*/
outline:none;
}
/*下拉框下面的item*/
QComboBox QAbstractItemView::item
{
height:20px;
color: rgb(255, 255, 255);/*字体颜色*/
}
/*下拉框item选中*/
QComboBox QAbstractItemView::item:selected
{
background:rgb(232,241,250);
color:rgb(2,65,123);
}
QLabel
{
color: rgb(255, 255, 255);
border-style:solid;/*边框样式 solid实线 none无边框 inset/outset 3D边框*/
border-width:1px;/*边框宽度像素*/
border-radius:4px;/*边框圆角半径像素*/
border-color:rgba(43,60,139);/*边框颜色*/
}
QTabWidget
{
    background-color:rgba(5,23,122);/*背景色*/
    color:rgb(255,255,255);/*字体颜色*/
}
QTabBar::tab
{
    background-color:rgba(5,23,122);/*背景色*/
    color:rgb(255,255,255);/*字体颜色*/
    font-size:12pt;/*字体大小*/
    height:30px; /*高度*/
    min-width:85px;/*宽度*/
    border-top-left-radius:4px;/*左上边框圆角半径像素*/
    border-top-right-radius:4px;/*右上边框圆角半径像素*/
    margin-right: 5px;/*右边距  右外边距*/
    padding-left:5px;/*左填充--左内边距*/
    padding-right:5px;/*右填充--右内边距*/
}
QTabBar::tab:hover
{
    background-color:rgba(5,23,200);/*背景色*/
}
QTabBar::tab:selected
{
    background-color:rgba(5,23,150)/*背景色*/
}
QTableView,QTableWidget{
    background-color:rgba(5,23,122);/*整个表格的背景色*/
    color:rgb(255,255,255);/*字体颜色*/
    selection-background-color:rgba(5,23,200);/*点击选中颜色*/
    border:1px solid #E0DDDC;/*边框为1像素,灰色*/
    gridline-color:lightgray;/*这个是表格的格子线的颜色,为亮灰*/
    font:bold 12pt;/*字体 字体大小*/
}
/*表格表头样式*/
QHeaderView::section{
    background-color:rgb(3,21,106);/*背景色*/
    border:0px solid #E0DDDC;/*先把边框宽度设为0,即隐藏所有表头边框*/
    border-bottom:1px solid #E0DDDC;/*然后只显示下边框,因为上边框和左右边框是整个Table的边框,都显示会有2px的边框宽度*/
    min-height:30px;;/*表头高度*/
    font-size:12pt;/*字体大小*/
}
QTreeWidget,QTreeView
{
    background-color:rgba(5,23,122);/*整个表格的背景色*/
    color:rgb(255,255,255);/*字体颜色*/
    selection-background-color:rgba(5,23,200);/*点击选中颜色*/
    font-size:12pt;/*字体大小*/
}
/*收起状态*/
QTreeWidget::branch:has-children:!has-siblings:closed,
QTreeWidget::branch:closed:has-children:has-siblings {
    border-image: none;
    image: url(:/image/add-line_horizontal.png);
}
/*展开状态*/
QTreeWidget::branch:open:has-children:!has-siblings,
QTreeWidget::branch:open:has-children:has-siblings  {
    border-image: none;
    image: url(:/image/array_down.png);
}
/*收起状态*/
QTreeView::branch:has-children:!has-siblings:closed,
QTreeView::branch:closed:has-children:has-siblings {
    border-image: none;
    image: url(:/image/add-line_horizontal.png);
}
/*展开状态*/
QTreeView::branch:open:has-children:!has-siblings,
QTreeView::branch:open:has-children:has-siblings  {
    border-image: none;
    image: url(:/image/array_down.png);
}

三,加载样式表

QFile file(":/user.qss");
file.open(QFile::ReadOnly);
if (file.isOpen())
{
    this->setStyleSheet(file.readAll());
}
file.close();

标签:qt,color,background,边框,样式表,rgba,border,模板,255
来源: https://blog.csdn.net/qq_45893999/article/details/122390000

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有