Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is the QSS model not possible? #47

Open
sohailsomani opened this issue May 13, 2016 · 4 comments
Open

Is the QSS model not possible? #47

sohailsomani opened this issue May 13, 2016 · 4 comments

Comments

@sohailsomani
Copy link

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
Copy link
Collaborator

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
Copy link
Author

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
Copy link

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
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

3 participants