Ableton / aqt-stylesheets

Apply CSS style sheets to QML applications
Other
215 stars 39 forks source link

Is the QSS model not possible? #47

Open sohailsomani opened 8 years ago

sohailsomani commented 8 years ago

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.

gck-ableton commented 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 ¯(ツ)

sohailsomani commented 8 years ago

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...)

machinekoder commented 5 years ago

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:

  1. When the StyleSet.name attached property is created, the object which this property is attached to is passed.
  2. Use this object reference and iterate over the properties of the object.
  3. Match the object properties with the corresponding CSS selectors.
  4. Connect the CSS property update signals with the property set slots of the object.
  5. Make sure the connections are closed when the object is destroyed.
  6. Update the property connections when the stylesheet changes.

Does this sound reasonable?

machinekoder commented 5 years ago

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.