当前位置:网站首页>QSS 选择器
QSS 选择器
2022-08-05 09:32:00 【M_qsqsqsq】
# 1.通配符选择器:匹配所有控件
'''
*{ // 用*号匹配所有控件
color:green;
}
'''
# 2.类型选择器(通过控件类型来匹配控件包含子类)
'''
QPushButton{
font-size:30px;
}
Btn{
font-size:30px;
}
'''
# 3.类选择器(通过控件类型匹配 不包括子类)
'''
.QPushButton{
font-size: 30px;
}
'''
# 4.ID选择器setObjectName #和字母之间不能有空格
'''
#btn{
background-color:green;
}
'''
# 5.属性选择器setProperty
'''
QPushButton[name="btn"]:hover{
background-color:red;
}
// 表示只要加上setProperty的所有name属性按钮都是红色背景,不影响其他无样式按钮的新建
QPushButton[name]:hover{
background-color:red;
}
'''
# 6.后代选择器(通过父控件直接或间接作用于子控件QPushButton)
'''
QWidget#box QPushButton{
background-color:green;
}
'''
# 7.子选择器(直接包含的子控件)
'''
QWidget#box>QLabel{
background-color:green;
}
'''
# 8.子控件选择器(主要用于组合控件中的一部分组件样式修改)
# 8.1.常见伪状态
'''
:checked # 控件被选中
:unchecked # 控件被取消选中
:hover # 鼠标停留
:pressed # 控件被按下
:focus # 获取到焦点
:disable # 失效控件
:enable # 有效控件
:indeterminate # checkBox或radioButton被部分选中
:on # 开启状态
:off # 关闭状态
'''
# 8.2.常用组合控件子控件
'''
QCheckBox, QRadioButton ::indicator
QComboBox ::drop-down
QSpinBox, QDateEdit, QTimeEdit, QDateTimeEdit ::up-button ::down-button ::up-arrow ::down-arrow
QSlider ::groove ::handle ::add-page ::sub-page
QProgressBar ::chunk
QScrollBar ::sub-line, ::add-line ::sub-page, ::add-page ::up-arrow, ::down-arrow ::left-arrow, ::right-arrow
QGroupBox ::title ::indicator
QTableView ::item
QHeaderView, QTableCornerButton ::section
QTreeView ::item ::branch
QHeaderView ::section
QTabWidget QTabWidget::pane QTabWidget::tab-bar QTabBar::tab QTabBar::close-button QTabBar::tear QTabBar::scroller QTabBar QToolButton::left-arrow QTabBar QToolButton::right-arrow
'''
'''
QCheckBox::indicator{
width: 20px;
height: 20px;
}
QCheckBox::indicator:checked{
image: url(y.png);
}
QCheckBox::indicator:unchecked{
image: url(n.png);
}
'''
# 9.选择器的组合使用(使用逗号隔开)
'''
#aaa,#bbb{
color: red;
}
'''
from PyQt5.Qt import *
import sys
class Btn(QPushButton) :
pass
class Window(QWidget) :
def __init__(self) :
super().__init__()
self.setWindowTitle("QSS选择器使用方法总结 - PyQt5中文网")
self.resize(600, 500)
self.func_list()
def func_list(self) :
self.func()
def func(self) :
box = QWidget(self)
box.setObjectName('box')
box1 = QWidget(box)
box1.setObjectName('box')
box1.resize(100, 60)
box1.move(250, 200)
box1.setStyleSheet('border:1px solid red')
label1 = QLabel('标签1', box)
label1.move(100, 200)
label1.resize(100, 50)
label1.setObjectName('aaa')
label2 = QLabel('标签2', box1)
label2.move(250, 200)
label2.resize(100, 50)
label2.setStyleSheet('color:red;')
label3 = QLabel('标签3', self)
label3.move(400, 200)
label3.resize(100, 50)
label3.setObjectName('bbb')
btn1 = QPushButton('按钮1', box)
btn1.move(100, 100)
btn1.resize(100, 50)
btn1.setProperty('name', 'btn1')
btn2 = QPushButton('按钮2', self)
btn2.move(250, 100)
btn2.resize(100, 50)
btn3 = QPushButton('按钮3', self)
btn3.setProperty('name', 'btn')
btn3.move(100, 300)
btn3.resize(100, 50)
btn4 = Btn('按钮4', self)
btn4.setObjectName('btn')
btn4.move(250, 300)
btn4.resize(100, 50)
print(box1.children())
ck = QCheckBox('选择正确答案', self)
ck.move(150, 400)
ck.resize(100, 40)
sb = QSpinBox(self)
sb.move(300, 400)
sb.resize(100, 40)
pass
if __name__ == '__main__' :
app = QApplication(sys.argv)
window = Window()
with open('qss11_2.qss', 'r', encoding='UTF-8') as f :
qApp.setStyleSheet(f.read())
window.show()
sys.exit(app.exec_())
/*qss 代码*/
/*
*{
color:green;
}
QPushButton{
font-size:30px;
}
Btn{
font-size:30px;
}
.QPushButton{
font-size: 30px;
}
#btn{
background-color:green;
}
QPushButton[name]:hover{
background-color:red;
}
QWidget#box QPushButton{
background-color:green;
}
QWidget#box>QLabel{
background-color:green;
}
QCheckBox::indicator{
width: 20px;
height: 20px;
background-color:green;
}
QCheckBox::indicator:checked{
image: url(y.png);
}
QCheckBox::indicator:unchecked{
image: url(n.png);
}
#aaa,#bbb{
color: red;
}
*/
边栏推荐
猜你喜欢
Redis源码解析:Redis Cluster
egg框架使用(一)
深度学习21天——卷积神经网络(CNN):天气识别(第5天)
leetcode: 529. 扫雷游戏
2.4G无线收发模块的应用
Analysis and practice of antjian webshell dynamic encrypted connection
Microservice Technology Stack
Xcode10的打包方式distribute app和启动项目报错以及Xcode 打包本地ipa包安装到手机上
Overall design and implementation of Kubernetes-based microservice project
Tanabata romantic date without overtime, RPA robot helps you get the job done
随机推荐
sql server中 两表查询 平均数 分组
我的杂记链接
15.1.1、md—md的基础语法,快速的写文本备忘录
蚁剑webshell动态加密连接分析与实践
js 图形操作一(兼容pc、移动端实现 draggable属性 拖放效果)
Creo 9.0 基准特征:基准平面
IDEA执行Test操作导致数据插入时出现了重复数据
5.部署web项目到云服务器
【LeetCode】623. Add a row to the binary tree
Qiu Jun, CEO of Eggplant Technology: Focus on users and make products that users really need
express hot-reload
Bias lock/light lock/heavy lock lock is healthier. How is locking and unlocking accomplished?
Oracle temporary table space role
Science bosses say | Hong Kong rhubarb KaiBin teacher take you unlock the relationship between the matrix and 6 g
七夕浪漫约会不加班,RPA机器人帮你搞定工作
在colab里怎样读取google drive数据
leetcode points to Offer 10- I. Fibonacci sequence
请问大佬们 ,使用 Flink SQL CDC 是不是做不到两个数据库的实时同步啊
深度学习21天——卷积神经网络(CNN):天气识别(第5天)
Advanced usage of C language