简体   繁体   English

如何在QML中捕获Spinbox变化值事件?

[英]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. 主题我在QML的Listview上显示数据,并带有项目的委托文本,标签和spinboxvalue元素。 When user change the value of spinbox I need to know it and make some deals. 当用户更改Spinbox的值时,我需要知道它并进行一些交易。 But MouseArea works beyond of Spinbox, not on spinned buttons, onClicked event doesn't exists. 但是MouseArea不能在Spinbox上使用,而不能在旋转按钮上使用,onClicked事件不存在。

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. 我在示例中找到onValueChanged,但在QML手册中找不到。

  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. 如果只想使用旋转框的当前值,只需在绑定中使用其value属性。

If you want to react to the value change, use the handler for the property's change signal, ie onValueChanged . 如果要对值更改做出反应,请使用属性的更改信号的处理程序,即onValueChanged

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM