在帮助中搜索qt style sheets
找到这句话:
If we want the property to apply only to one specific QLineEdit, we can give it a name using QObject::setObjectName() and use an ID Selector to refer to it:
意思是如果不想子控件继承父控件,就在父控件加#
if(m_MainWidget.objectName().isEmpty()){ m_MainWidget.setObjectName("backLineEdit"); } m_MainWidget.setStyleSheet("QWidget#backLineEdit{border-image:url(:/image/background.jpg);}");
m_MainWidget是父控件,先setObjectName一个名,随便起一个,然后#加上这个名字。这样子控件就不会继承父控件的样式了。
原文地址:https://www.cnblogs.com/smh2015/p/11819762.html
时间: 2024-11-03 15:19:05