Open sohailsomani opened 8 years ago
Hi, yes that would be the better situation. Actually I don't understand why CSS (or QSS) hasn't be extended to QtQuick in the first place, but there are some hints in various readmes or forum threads that this was not by accident, but wanted. Anyway. Supporting CSS/QSS natively (i.e. without properties) would require quite some changes to the QML kernel itself. Compared to this projects (a) this would be a major undertaking (b) it is unclear whether it would be accepted upstream (see above) and (c) if not, would require custom Qt builds to work.
So I guess for now, it will stay this way ¯(ツ)/¯
I suppose you're right. It's too bad... Thanks for the explanation. If you happen to come across those readmes or forum threads, it would be so helpful if you sent them my way (or attached them here...)
I'm trying out Aqt-Stylesheets right now and I thought exactly the same. Defining the properties is redundant.
It should be possible to auto-infer the CSS/property names from the underlying QtObject via the property() API and maybe a little bit of QMetaObject fiddling.
Here is how I would do it:
StyleSet.name
attached property is created, the object which this property is attached to is passed.Does this sound reasonable?
I looked into this a little bit. Inside the attached QML component you can do something along the lines of:
for (int i = 0; i < object->metaObject()->propertyCount(); ++i) {
const auto property = object->metaObject()->property(i);
qDebug() << property.name();
}
Which gives you access to all the properties of an object. Then continue with step 3 of the steps above.
Of course, this will only work for QML items where we attach a property. So in case we don't set a StyleSet.name
we could set for example StyleSet.attached: true
, which I think would be a good compromise over connecting the properties by hand.
This is a question, not an issue. With the understanding that perfect is the enemy of good...
Is there a technical reason why the QSS approach could not have worked here? Specifically, it is super redundant to define selectors in CSS files and then request the property values in the appropriate elements (what if you get that wrong?) With Qt Style Sheets, you do not need to change your widget code to apply the new properties.
Thank you for making your code available.