0
votes

I try to use QML ProgressBar. Here is the documentation https://doc.qt.io/qt-5/qml-qtquick-controls-styles-progressbarstyle.html#details

I try this code

import QtQuick 2.14
import QtQuick.Controls 2.15
import QtQuick.Window 2.14
import QtQuick.Controls.Styles 1.4

Window {
    id: root
    width: 300; height: 300

    ProgressBar {
        value: 0.5
        style: ProgressBarStyle {
            background: Rectangle {
                radius: 2
                color: "lightgray"
                border.color: "gray"
                border.width: 1
                implicitWidth: 200
                implicitHeight: 24
            }
            progress: Rectangle {
                color: "lightsteelblue"
                border.color: "steelblue"
            }
        }
    }
}

But I have the error invalid property name "style". What i doing wrong?

2

2 Answers

4
votes

You're mixing the styling from Qt Quick Controls 1 with Qt Quick Controls 2. To customise a ProgressBar in Qt Quick Controls 2, see this page:

import QtQuick 2.12
import QtQuick.Controls 2.12

ProgressBar {
    id: control
    value: 0.5
    padding: 2

    background: Rectangle {
        implicitWidth: 200
        implicitHeight: 6
        color: "#e6e6e6"
        radius: 3
    }

    contentItem: Item {
        implicitWidth: 200
        implicitHeight: 4

        Rectangle {
            width: control.visualPosition * parent.width
            height: parent.height
            radius: 2
            color: "#17a81a"
        }
    }
}
0
votes
import QtQuick.Controls 2.15
...
import QtQuick.Controls.Styles 1.4

You are using two different versions of QtQuick here, ie. you have imported ProgressBar from QtQuick.Controls 2.15 which does not have a style property (https://doc.qt.io/qt-5/qml-qtquick-controls2-progressbar.html).

More information about differences can be found here: https://doc.qt.io/qt-5/qtquickcontrols2-differences.html