Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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()
like image 700
Catty2327 Avatar asked Dec 22 '25 20:12

Catty2327


1 Answers

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.

like image 74
Kevin Krammer Avatar answered Dec 24 '25 09:12

Kevin Krammer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!