【问题标题】:how to catch Spinbox event of change value in QML?如何捕获 QML 中更改值的 Spinbox 事件?
【发布时间】:2016-11-19 11:06:35
【问题描述】:

主题 我在 QML 的 Listview 上显示我的数据,其中包含项目的委托文本、标签和 spinboxvalue 元素。当用户更改 spinbox 的值时,我需要知道它并进行一些交易。但是 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")
                        }
                    }

顺便问一下,如何在控制台日志中输出当前日期时间?

我在示例中找到了 onValueChanged,但在 QML 手册中没有找到它。

  SpinBox {
            id: fontSizeSpinBox
            activeFocusOnPress: false
            implicitWidth: 50
            value: 0
            property bool valueGuard: true
            onValueChanged: if (valueGuard) document.fontSize = value
        }

我发现打印当前时间戳

   Qt.formatTime(new Date()

【问题讨论】:

  • onValueChangedproperty change signal handler
  • 谢谢。它是所有类对象的公共信息。现在我了解 Changed where 是属性的名称

标签: qt events qml qtquick2 qtquickcontrols


【解决方案1】:

如果您只想使用旋转框的当前值,只需在绑定中使用其value 属性即可。

如果您想对值更改做出反应,请使用属性更改信号的处理程序,即onValueChanged

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-26
    • 1970-01-01
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多