有求必应

导航

Qt子控件样式不生效,因为父控件样式设定

在帮助中搜索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一个名,随便起一个,然后#加上这个名字。这样子控件就不会继承父控件的样式了。

posted on 2019-11-08 13:51  名侦探江户川  阅读(1637)  评论(0编辑  收藏  举报