How to create a QStyle from a `.css` file?
-
There exists QApplication::setStyleSheet() and QWidget::setStyleSheet(), but I can't find a way to create a
QStyle
from a.css
file, I want to make aQStyle
with some styles predefined in a.css
file and some others computed at runtime.
So, is there a way to achieve it? -
@Sauntor Qt Style Sheets are not CSS although there is some similarity.
Assuming you put some valid Qt style sheet rules in a text file, or resource, then all you need to do is open the file, read the content into a string, and call setStylesheet() with the string. There's no great mystery involved.
Edit: QStyle is an abstract class used only to build concrete classes implementing styles. These are not run-time creatable entities.
-
@Sauntor
There isn't a way to do this. Other than coding whatever you want manually by inspecting the CSS and finding equivalents. And CSS has rules/selectors for when to apply its content, there is no equivalent for that withQStyle
, again you have to code it yourself. -
Hi,
To add to my fellows, are you thinking of something like the style that is used when you call setStyleSheet ?
If so, you will to write the parser yourself and also be aware that not everything that is defined in the CSS specification can be applied to desktop controls.
-
This post is deleted!