2016-11-19 355 views
0

Subj 我使用委託文本,標籤和項目的spinboxvalue元素在QML'Listview上顯示我的數據。當用戶更改spinbox的值時,我需要知道它並進行一些交易。但MouseArea的作品超出了Spinbox,而不是旋轉的按鈕,onClicked事件不存在。如何捕捉QML中的變化值的Spinbox事件?

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() 
+1

'onValueChanged'是一個[property change signal handler](http://doc.qt.io/qt-5/qtqml-syntax-signals.html#property-change-signal-handlers)。 – mcchu

+0

謝謝。它是所有類對象的通用信息。 現在我明白了 on 更改是屬性的名稱 –

回答

0

如果你只想用紡紗器的電流值,只需使用其value屬性的綁定。

如果您想對價值變化做出反應,請使用屬性更改信號的處理程序,即onValueChanged