qss 对子控件的设置样式 使用setProperty


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

代码:

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

void CustomLabelWidget::enterEvent(QEvent *)
{
textLabel->setProperty("labelState", "hover");  // 属性是自定义的

textLabel->style()->unpolish(iconLabel);
textLabel->style()->polish(textLabel);

textLabel->update();

setStyle(QApplication::style());  //这句必须加上,否则样式设置失败
}

void CustomLabelWidget::enterEvent(QEvent *)
{
textLabel->setProperty("labelState", "none");  // 属性是自定义的

textLabel->style()->polish(textLabel);

textLabel->update();

setStyle(QApplication::style());  //这句必须加上,否则样式设置失败


}

 

qss样式设置如下:

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

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


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM