QT开发中,需要设置多种多样的控件表现形式,QT实现的styleSheet能够满足多种多样的场景,这里简单的记录下一些我常用的
- 设置透明背景,鼠标悬浮时,设置背景色:
pushButton->setStyleSheet("QPushButton {background: transparent;border: none;} QPushButton:hover {background-color: rgba(200, 200, 200, 255);}")
//这里设置pushButton的背景,正常情况下背景设置为透明,当有鼠标悬浮时,设置背景色rgba(200, 200, 200, 255)
- 根据控件的property值设置对应的背景:
//widget是一个父控件,他的子对象可以根据property值,设置对应的样式
widget->setStyleSheet(