QML custom style

Joakim Bygdell j.bygdell at gmail.com
Tue Jul 18 22:42:30 PDT 2017


On 18 July 2017 at 22:10, Rick Walsh <rickmwalsh at gmail.com> wrote:

> Dirk and Jocke (especially),
> I can see you've done a lot over the past few weeks to make the mobile UI
> much more attracted.  Have you considered using a custom Subsurface style
> (falling back to Material) to make it more efficient to theme the QML
> controls?  It would be easier to customize the controls in one place, and
> have the change made consistently throughout, following the guidance in:
> https://doc.qt.io/qt-5/qtquickcontrols2-customize.
> html#creating-a-custom-style
>

The thing is that we are not just dealing with the material theme here,
Kirigami has it own theme as well.
And the interaction between these two are in some cases a bit special as
there are parts where the material theme decides what the user sees and
other parts where the Kirigami decides how things will look.
Right now we just tell the app that for material light theme to set a few
parameters to our own colors, the rest is actually handled by the Kirigami
theme.


>
> In the attached patch I have done that for the button controls (only used
> on DownloadFromDiveComputer.qml) moving the styling into
> SubsurfaceStyle/Button.qml, but it would not be hard to do it for the other
> controls.  Using the Button as an example, we could then add code to make
> the button depress and change colour when down, and only have to add the
> code in one place.
>
> The big problem now, is that the only way I've been able to use the custom
> style is to select it from the command line (testing on desktop):
> ./subsurface-mobile -style /home/rick/src/subsurface/mobile-widgets/qml/
> SubsurfaceStyle
> Clearly that is useless for the mobile app.  I believe we should also be
> able to use QQuickStyle::SetStyle to set it from within the app (see
> https://doc.qt.io/qt-5/qquickstyle.html), but the following doesn't work
> for me, either with or with setting the fallback style.  Maybe the problem
> is that I'm using Qt5.7, but I'm not sure.
>
> diff --git a/subsurface-mobile-helper.cpp b/subsurface-mobile-helper.cpp
> index 68dd228b..cd1df6c6 100644
> --- a/subsurface-mobile-helper.cpp
> +++ b/subsurface-mobile-helper.cpp
> @@ -14,6 +14,7 @@
>
>  #include <QQuickWindow>
>  #include <QScreen>
> +#include <QQuickStyle>
>  #include <QQmlApplicationEngine>
>  #include <QQmlContext>
>  #include <QSortFilterProxyModel>
> @@ -43,6 +44,10 @@ void run_ui()
>         qmlRegisterType<DownloadThread>("org.subsurfacedivelog.mobile",
> 1, 0, "DCDownloadThread");
>         qmlRegisterType<DiveImportedModel>("org.subsurfacedivelog.mobile",
> 1, 0, "DCImportModel");
>
> +       // set style for custom constrols
> +       QQuickStyle::setStyle(":/SubsurfaceStyle");
> +       QQuickStyle::setFallbackStyle("Material");
> +
>         QQmlApplicationEngine engine;
>         KirigamiPlugin::getInstance().registerTypes();
>  #if __APPLE__
>
> Cheers,
>
> Rick
>
> _______________________________________________
> subsurface mailing list
> subsurface at subsurface-divelog.org
> http://lists.subsurface-divelog.org/cgi-bin/mailman/listinfo/subsurface
>
>


-- 

Jocke
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.subsurface-divelog.org/pipermail/subsurface/attachments/20170719/dce1760d/attachment.html>


More information about the subsurface mailing list