开发者

Setting Background Stylesheet to QWidget shows on all controls

开发者 https://www.devze.com 2023-04-04 13:49 出处:网络
I have set the following CSS to the QWidget Stylesheet: QWidget { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #00b7ea, stop: 1 #009ec3); /* C开发者_高级运维hrome10+,Safari5.

I have set the following CSS to the QWidget Stylesheet:

QWidget { background-color: qlineargradient(x1: 0, y1: 0, x2: 0, y2: 1, stop: 0 #00b7ea, stop: 1 #009ec3); /* C开发者_高级运维hrome10+,Safari5.1+ */ }

It works fine, but when I put a button or any other control on the canvas, I get the same background colour included in the elements.

Setting Background Stylesheet to QWidget shows on all controls

Can someone help me fix this.

I've tried using a QFrame but I always get a border around the Frame like this:

Setting Background Stylesheet to QWidget shows on all controls


When you set a style sheet for a QWidget, the style sheet is applied to that QWidget and the entire child hierarchy of that widget. Since you are using QWidget as a selector, the style will be applied to any QWidget or QWidget subclass. A QPushButton is a subclass of QWidget, so the style rule is applied to it.

There are many ways you could single out just the main QWidget with a selector. In this case, it might be easiest just to use .QWidget which will target only QWidgets and not QWidget subclasses.

If you end up having other QWidgets in the child hierarchy, you can be more selective by identifying the class and objectName property using Classname#objectName.

You should read this section of the Qt docs for more info.

0

精彩评论

暂无评论...
验证码 换一张
取 消