Nominate our 2022 Qt Champions!

[SOLVED] ProgressBarStyle in a styling Singleton

  • Hi,

    I've been trying various ways to switch out the style of a ProgressBar to indicate an error state. I've tried setting the style in a PropertyChanges, both created there or referenced by id, I've tried using Bindings as well as Loaders and Bindings and finally now a style singleton. I like the Singleton approach best, but I cannot make it work either. Here's my Singleton's code:

    @pragma Singleton
    import QtQuick 2.2
    import QtQuick.Controls 1.1
    import QtQuick.Controls.Styles 1.1

    QtObject {
    property ProgressBarStyle progressBarErrorStyle: ProgressBarStyle {
    background: Rectangle {
    radius: 2
    color: "lightgray"
    border.color: "gray"
    border.width: 1
    implicitWidth: 200
    implicitHeight: 20
    progress: Rectangle {
    color: "orangered"
    border.color: "red"

    The problem is, when I use progressBarErrorStyle in any of my QML files, its type is ProgressBarStyle_QMLTYPE_17.

    I've asked a couple of questions on Stackoverflow related to what I'm trying to do, so I figured I'd try here...

    What am I missing, is it even possible to swap out a ProgressBar's style at runtime?

  • The solution was to add a qmldir file with:

    @singleton Style Style.qml@

  • The solution was to add a qmldir file with:

    @singleton Style Style.qml@

Log in to reply