向Qt样式表添加特异性时丢失样式 [英] Losing style when adding specificity to a Qt stylesheet

查看:202
本文介绍了向Qt样式表添加特异性时丢失样式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的代码:

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

稍后在代码中应用SS,如下所示:

The SS is applied later in the code like this:

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

它像一个冠军,除了边框渗入一个子QFrame。如果我通过用下面的括号添加特殊性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 { }

STYLE_SHEET停止应用。它解决了向下流到孩子QFrame,但我的QWidget失去了它的风格。

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?

推荐答案

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

这篇关于向Qt样式表添加特异性时丢失样式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆