加入特异性Qt的样式表时丢失的风格(Losing style when adding specifi

2019-10-21 22:39发布

这里是我的代码:

const QString STYLE_SHEET = "background-color: rgba(x,x,x,y);"
                            "border: 1px solid gray;"
                            "border-radius: 0px;"
                            "border-top: 1px solid red;"
                            "border-bottom: 1px solid blue;"
                            "border-radius: 0px;";

党卫军在这样的代码后加:

QWidget * myWidget;
myWidget = new QWidget(parent);
myWidget.setObjectName("myWidgetName");
myWidget.setStyleSheet(STYLE_SHEET);

它的工作原理相似,但边境渗入孩子QFrame一个冠军。 如果我用下面的包围它添加特异性STYLE_SHEET:

const QString QWidget#myWidgetName { }

该STYLE_SHEET不再适用。 它解决了流血倒在孩子QFrame但我QWidget的失去了它的风格。 什么是好作风没有一个QWidget?

Answer 1:

const QString STYLE_SHEET = "QWidget#myWidgetName {\n"
                            "    background-color: rgba(x,x,x,y);\n"
                            "    border: 1px solid gray;\n"
                            "    border-radius: 0px;\n"
                            "    border-top: 1px solid red;\n"
                            "    border-bottom: 1px solid blue;\n"
                            "    border-radius: 0px;\n"
                            "}\n";


文章来源: Losing style when adding specificity to a Qt stylesheet