[英]How to add a CSS Style Class to a QWidget
In JavaFx I can easily add a CSS style class as follows:在 JavaFx 中,我可以轻松地添加一个 CSS 样式类,如下所示:
Scene scene = new Scene(new Group(), 500, 400);
scene.getStylesheets().add("path/stylesheet.css");
......
Label label = new Label("Cool Looking Styled Label");
label.getStyleClass().add("my-label-style");
css CSS
.my-label-style {
-fx-font: 16px "Serif";
-fx-padding: 10;
-fx-background-color: #CCFF99;
}
How can I go about adding a style class to a QWidget , QLabel
, for example?例如,如何将样式类添加到QWidget 、 QLabel
?
label->setProperty("class", "my-label-style");
Then in a CSS you can call it normally by:然后在 CSS 中,您可以通过以下方式正常调用它:
.my-label-style {
[..]
}
The method is in the QWidget base class;该方法在QWidget基类中; it's QWidget::setStyleSheet.它是 QWidget::setStyleSheet。
you have two ways to do that你有两种方法可以做到这一点
coding编码
Form ui窗体用户界面
but all css code are not supported,you need to see documentation of stylesheet但是不支持所有的css代码,你需要看stylesheet的文档
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.