Losing style when adding specificity to a Qt style

2019-08-14 08:00发布

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条回答
【Aperson】
2楼-- · 2019-08-14 08:28
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";
查看更多
登录 后发表回答