← Back to team overview

ubuntu-phone team mailing list archive

[SDK][Theming] Styling a compound widget

 

Hi all,

This email is going to run on a bit, so let me put my questions here at the top and motivate them afterwards:

1) Is it possible to adjust the style of a single compound widget? (That is, a QML element with several sub-elements. I don't know the terminology here.)

2) If not (and I haven't found one), should there be?

I'm working on an epub reader for the app showdown [1]. One of the options I provide is the font in which the epub will be displayed. I want to do this with an OptionSelector, and I'd like to display the name of each font in that font. It looks like this is impossible with the SDK as it currently stands. (Please correct me if I'm wrong.)

With simple QML widgets, like a Rectangle, you can adjust the properties of the widget to change its styling. But the widget I need to adjust, an OptionSelectorDelegate, is a compound widget -- the text is in a Label inside of the OptionSelectorDelegate, and there's no way for me to access this. These Labels don't have ids, and even if they did those ids wouldn't be accessible outside of that .qml file, for some reason.

I came up with a simple fix to this: Give the Labels ids, and then give the OptionSelectorDelegate properties referencing the label. Then when I make an OptionSelectorDelegate, I can adjust the font of the label through the textLabel.fontFamily property. I've written up a patch and submitted it to Launchpad [2].

I asked about this on IRC, and mzanetti opined that this was not the right approach. Internals shouldn't be exposed like this. And while I disagree, this is not an unreasonable position. Instead, mzanetti suggested that the OptionSelectorDelegate should become themable, and then I could provide my own theme to do the styling.

It may be that it should be themable, but this wouldn't solve my problem. I don't want to redo the theming of the widget; I just want to tweak the font. I could do this, theoretically, by creating a new widget based on the OptionSelectorDelegateStyle widget and tweaking the font there. But this runs into three problems:

1) Not all the *Style widgets are exposed in the Theme directories. (I recently ran into this problem when trying to theme a Slider; see [3].)

2) I would have to inherit from a specific theme. If that changes in the future, due to system changes or user choice, my styling would be completely wrong.

3) I would still need access to the internal Label of the style widget, which is the very thing that got us going down this path!

Hence my questions: Is there a way to set the font in an OptionSelectorDelegate? There doesn't seem to be. Should there be? I think so. How should this work? This I don't know enough about to comment.

Thanks,
Robert

[1] https://github.com/rschroll/beru
[2] https://bugs.launchpad.net/ubuntu-ui-toolkit/+bug/1220533
[3] https://github.com/rschroll/beru/commit/927b2fd377d7cc86b0633a2707b03c3a79a330db



Follow ups