【翻译 + 整理】Qt样式表详解(8):属性类型的一些知识点

本文介绍了如何在QLabel中同时设置盒子模式的边框颜色和宽度,包括一次性设定多方向颜色、使用QPalette调色板角色,以及如何运用线性、辐射和锥形渐变来美化界面。还涵盖了颜色的不同表示方式和背景渐变的详细示例。
摘要由CSDN通过智能技术生成

1、设置盒子模式相关颜色类的属性可以一次设置多个方向的,顺序为上、右、下、左。如果未指定左侧颜色,则将其与右侧颜色相同。 如果未指定底色,则将其与顶色相同。 如果未指定正确的颜色,则该颜色应与顶部的颜色相同。例如:

 QLabel { border-color: red }   /* red red red red */
 QLabel { border-color: red blue } /* red blue red blue */
 QLabel { border-color: red blue green } /* red blue green blue */
 QLabel { border-color: red blue green yellow } /* red blue green yellow */

2、盒子模式尺寸相关的属性也有类似的规则:

 QLabel { border-width: 1px }                    /* 1px 1px 1px 1px */
 QLabel { border-width: 1px 2px }                /* 1px 2px 1px 2px */
 QLabel { border-width: 1px 2px 3px }            /* 1px 2px 3px 2px */
 QLabel { border-width: 1px 2px 3px 4px }        /* 1px 2px 3px 4px */

3、颜色设置可以有多种方式:

 QLabel { border-color: red }                      /* opaque red */
 QLabel { border-color: #FF0000 }                  /* opaque red */
 QLabel { border-color: rgba(255, 0, 0, 75%) }     /* 75% opaque red */
 QLabel { border-color: rgb(255, 0, 0) }           /* opaque red */
 QLabel { border-color: rgb(100%, 0%, 0%) }        /* opaque red */
 QLabel { border-color: hsv(60, 100%, 100%) }      /* opaque yellow */
 QLabel { border-color: hsva(240, 255, 255, 75%) } /* 75% blue */
 QLabel { border-color: hsl(60, 100%, 50%) }       /* opaque yellow */
 QLabel { border-color: hsla(240, 255, 50%, 75%) } /* 75% blue */

4、颜色、背景等可以设置为渐变类型:QT绘图:渐变 这个用来设置窗口背景是不错用法。

  • qlineargradient:线性渐变。
  • qradialgradient:辐射渐变。
  • qconicalgradient:锥形渐变。
QWidget
{
    background: qlineargradient(x1:0, y1:0, x2:1, y2:1,
                 			    stop:0 white, stop: 0.4 gray, stop:1 green)
}

QWidget
{
    background: qconicalgradient(cx:0.5, cy:0.5, angle:30,
                 			     stop:0 white, stop:1 #00FF00)
}

 焦点在(0,0)

QWidget
{
    background: qradialgradient(cx:0, cy:0, radius: 1,
                                fx:0, fy:0, stop:0 white, stop:1 green)
}

 

焦点在(0.5,0.5):

QWidget
{
    background: qradialgradient(cx:0, cy:0, radius: 1,
                                fx:0.5, fy:0.5, stop:0 white, stop:1 green)
}

5、颜色类的属性可以为QWidget的QPalette的部分调色板角色的颜色。实用QPalette

支持设置如下角色:

  • alternate-base 
  • base 
  • bright-text 
  • button 
  • button-text 
  • dark 
  • highlight 
  • highlighted-text 
  • light 
  • link 
  • link-visited 
  • mid 
  • midlight 
  • shadow 
  • text 
  • window 
  • window-text

例:

 QPushButton { color: palette(dark); }

6、border-radius等相关类似的属性可以设置2个值。如果仅指定一个值,则将其用作定义角的四分之一圆的半径。 如果指定了两个值,则第一值是四分之一椭圆的水平半径,而第二值是垂直半径。

QPushButton{
    border-radius:60px;
}

QPushButton{
	border-radius:60px 10px;
}

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值