qss 对子控件的设置样式 使用setProperty --Qt 之 QSS(动态属性)

https://blog.csdn.net/liang19890820/article/details/51693956 学习了

代码:

当鼠标划过控件时,设置样式

void CustomLabelWidget::enterEvent(QEvent *)
{
iconLabel->setProperty("labelState", "hover");
textLabel->setProperty("labelState", "hover");  // 属性是自定义的
setStyle(QApplication::style());  //这句必须加上,否则样式设置失败
}

void CustomLabelWidget::enterEvent(QEvent *)
{
iconLabel->setProperty("labelState", "none");
textLabel->setProperty("labelState", "none");  // 属性是自定义的
setStyle(QApplication::style());  //这句必须加上,否则样式设置失败
}

qss样式设置如下:

QLabel#objectname[labelState="hover"]{
image: url(:/Resouces/images/refresh.png);
}

/*鼠标划过按钮显示的文字样式*/
QLabel#objectname[labelState="hover"]{
color:rgb(0 ,255 , 252);
}

猜你喜欢

转载自www.cnblogs.com/wangjian8888/p/10432540.html