Losing style when adding specificity to a Qt stylesheet

流过昼夜 提交于 2019-12-11 12:50:22

问题


Here's my code:

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;";

The SS is applied later in the code like this:

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

It works like a champ except that the borders bleed into a child QFrame. If I add specificity to STYLE_SHEET by bracketing it with the following:

const QString QWidget#myWidgetName { }

The STYLE_SHEET ceases to apply. It solves the bleed down to the child QFrame but my QWidget loses its style. And what good is a QWidget without style?


回答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";


来源:https://stackoverflow.com/questions/28570389/losing-style-when-adding-specificity-to-a-qt-stylesheet

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!