Invalid property name "minimum" etc. (M16) - qt

Slider
{
id: sldRed
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 80
width: 450
minimum: 0
maximum: 100
value: 0
step: 1
backgroundEmpty: "lightgray"
backgroundFull: "red"
pressCircle: "red"
onValueChanged:
{
// pwmRed.setPwmValue(value);
}
}
when I compile it gives the following errors:
Invalid property name "minimum". (M16)
Invalid property name "maximum". (M16)
Invalid property name "step". (M16)
Invalid property name "backgroundEmpty". (M16)
Invalid property name "pressCircle". (M16)
Included in the project is Slider.qml with all the properties in question
import QtQuick 2.2
Item {
id:slider
height: heightSlider
signal released(int value)
signal pressed()
property real value: 1
onValueChanged: updatePos();
property real minimum: 1
property real maximum: 1
property real step: 1
property int xMax: width - handle.width
onXMaxChanged: updatePos();
onMinimumChanged: updatePos();
property color backgroundEmpty: "lightgrey";
property color backgroundFull: "#39F724";
property real backgroundopacity: 1;
property real backgroundopacityFull: 1;
property color pressCircle: "#39F724"
property color handleGrad1: "lightgray"
property color handleGrad2: "gray"
property real heightSlider: 10
property real fullCircle: 30
property real circleWidth: 70
property real circleHeight: 70
......
......
......
}
I added Slider.qml with the properties:
import QtQuick 2.2
Item {
id:slider
height: heightSlider
signal released(int value)
signal pressed()
property real value: 1
onValueChanged: updatePos();
property real minimum: 1
property real maximum: 1
property real step: 1
property int xMax: width - handle.width
onXMaxChanged: updatePos();
onMinimumChanged: updatePos();
property color backgroundEmpty: "lightgrey";
property color backgroundFull: "#39F724";
property real backgroundopacity: 1;
property real backgroundopacityFull: 1;
property color pressCircle: "#39F724"
property color handleGrad1: "lightgray"
property color handleGrad2: "gray"
property real heightSlider: 10
property real fullCircle: 30
property real circleWidth: 70
property real circleHeight: 70
......
......
......
}

Related

ListModel in repeater

When using a ListModel for a repeater, if a property is not set in the first element of the model, then it is not considered in the following elements. Why?
import QtQuick 2.7
import QtQuick.Controls 2.3
Item{
id: root
property var labels: ListModel{}
Button{
text: 'create labels'
onClicked:{
root.labels.append({})
root.labels.append({name: '2'})
root.labels.append({name: '3'})
}
}
Column{
x: 10
y: 200
spacing: 2
Repeater{
model: root.labels
Button{
width: 120
height: 30
text: model.name
}
}
}
}
This code is ok:
....
onClicked:{
root.labels.append({name: '1'})
root.labels.append({})
root.labels.append({name: '3'})
}
....
It doesn't work because the roles of the ListModel get evaluated based on its first element. The property of the first element defines the roles of the model. If you had other properties in the following elements, those will be ignored.
That behavior is the default one when the dynamicRoles property is not set to true.
When set to true, the model will recalculate its roles for each inserted element and emit a modelReset every time the roles change. This is costly and not generally needed so its disabled by default.

qt: invalid property name "progress". (M16)

you can find my code example below. When I try to add "progress" qml says thatinvalid property name "progress". (M16) How can I fix this problem
ProgressBar {
x:300
y: 200
value: 0.5
background: Rectangle {
radius: 10
color: "red"
border.color: "gray"
border.width: 1
implicitWidth: 200
implicitHeight: 10
}
progress: Rectangle{
}
}
Assuming you'd like to customize the progress indicator with in the ProgressBar: use the contentItem property. See the documentation for more information.

Can We have a SwipeView by using PathView?

In QML Swipe View is not bidirectional.So I need a swipe view
A code sample will be very beneficial for me.
I need to keep only 3 items in my view & at a time only item should be visible & on swiping the view in either way left or right element should be on center.
This code solves half problem That is why I posted as answer
import QtQuick 2.0
Item {
property alias model: view.model
property alias delegate: view.delegate
property alias currentIndex: view.currentIndex
property real itemHeight: 60
clip: true
PathView {
id: view
anchors.fill: parent
snapMode: PathView.NoSnap
pathItemCount: height/itemHeight
preferredHighlightBegin: 0.5
preferredHighlightEnd: 0.5
dragMargin: view.width/5
path: Path {
startY: view.width/4; startX:-itemHeight/2 -50
PathLine { y: view.width/4; x: (view.pathItemCount*itemHeight + 3*itemHeight) }
}
}
}
And this is My Item :
Item{
id:widgetMain
width :480
height : 240
property int delegateHeight: widgetMain.height
property int delegateWidth : widgetMain.width
Spinner {
id: spinner
width: parent.width;
height: parent.height;
focus: true
model: ["qrc:/Tile1.qml",
"qrc:/Tile2.qml"
,"qrc:/Tile3.qml"]
itemHeight: 150
delegate: Loader {
width: delegateWidth
height: delegateHeight
source: modelData
}
}
}
Now If I swipe towards any direction, It shows only 1 tile in the view. & When my drag reaches to half way, then the tile removes & shifts to last.
Here I want to display that one tile is swiping & 2nd tile is coming from behind(Just like a Swipe view).
Now can you help me please?

how to catch Spinbox event of change value in QML?

Subj
I show my data on QML' Listview with delegated text, labels, and spinboxvalue elements of item. When user change the value of spinbox I need to know it and make some deals. But MouseArea works beyond of Spinbox, not on spinned buttons, onClicked event doesn't exists.
SpinBox {
id: goodsCountSpinBox
leftPadding: 1
rightPadding: 1
value: model.goodsCount
implicitWidth: 100
anchors.right: dataRow.right
MouseArea {
anchors.fill: parent
onClicked: {
listView.currentIndex = index; //Change the current selected item to the clicked item
console.log("SpinBox::MouseArea::onClicked")
}
}
By the way, and how to out current datetime in console log?
I found onValueChanged in examples but I don't find it in QML manuals.
SpinBox {
id: fontSizeSpinBox
activeFocusOnPress: false
implicitWidth: 50
value: 0
property bool valueGuard: true
onValueChanged: if (valueGuard) document.fontSize = value
}
I found to print current timestamp
Qt.formatTime(new Date()
If you want to just use the current value of the spinbox, just use its value property in a binding.
If you want to react to the value change, use the handler for the property's change signal, i.e. onValueChanged.

How to set initial value of a custom slider in qml?

I am using Qt 5.4.1. I have made a custom slider element to be used in other qml components like so:
Slider.qml
import QtQuick 2.4
import QtQuick.Controls 1.3
import QtQuick.Controls.Styles 1.3
Item {
id: root
width: 150
height: 30
property int val: slider.value
property int maxVal: slider.maximumValue
property int minVal: slider.minimumValue
property int step: slider.stepSize
Slider {
id: slider
anchors.margins: 20
stepSize: step
maximumValue: maxVal
minimumValue: minVal
style: customStyle
// onValueChanged: print("From Slider.qml" ,value)
}
Component {
id: customStyle
SliderStyle {
handle: Rectangle {
width: 20
height: 12
antialiasing: true
color: Qt.lighter("#468bb7", 1.2)
}
groove: Item {
implicitHeight: root.height
implicitWidth: root.width
Rectangle {
height: 8
width: parent.width
anchors.verticalCenter: parent.verticalCenter
color: "#847878"
opacity: 0.8
Rectangle {
antialiasing: true
radius: 1
color: "#1a0d0d"
height: parent.height
width: parent.width * control.value / control.maximumValue
}
}
}
}
}
}
And in another file test.qml I am using this slider like so
test.qml
import QtQuick 2.3
Rectangle {
id: test
width: 640; height: 480
Slider {
id: slider
width: 300
height: 30
anchors.centerIn: parent
maxVal: 1000
minVal: 0
step: 50
val: 500 // when commented out, onValChanged is triggered on sliding
onValChanged: print(val)
}
}
I want to set the slider to an initial value when instantiated in test.qml, using the property val. But when I set initial value, onValChanged does not get triggered when sliding the slider. But when I comment that line out (val: 500), onValChanged is triggered when the slider is slid, but the slider starts with initial value of 0 which I don't want. I don't understand what I am doing wrong here!
The setting of the property val to a specific value overrides the binding, as defined in your slider component. Once the binding is lost, any update of the slider is not delivered to val resulting in the behaviour you experienced. On the other way around, if you don't set the property the binding is maintained, i.e. as the slider value changes the value of val changes accordingly, triggering the signal.
That's not the way to go in this case, also because you are adding a set of properties which simply exposes inner properties of Slider. Just use properties alias:
Property aliases are properties which hold a reference to another property. Unlike an ordinary property definition, which allocates a new, unique storage space for the property, a property alias connects the newly declared property (called the aliasing property) as a direct reference to an existing property (the aliased property).
Rewrite your properties inside Slider.qml as follows:
property alias val: slider.value
property alias maxVal: slider.maximumValue
property alias minVal: slider.minimumValue
property alias step: slider.stepSize
This way val is slider.value and setting it to 500 directly affect the slider without breaking any binding.
On a sidenote, you can also for example write
property alias maximumValue: slider.maximumValue
i.e. expose inner properties with their very same name to maintain the consistency in API naming.

Resources