2015-08-30 15 views
1

我知道如何綁定到根表TableView信號,如onClicked,但由於onSelectionChanged是它的selection屬性的信號,我不知道如何綁定到它。QML TableView:如何綁定到selection.onSelectionChanged()

我想我肯定可以使用Connections綁定到它,但下面的代碼沒有工作:

編輯Connections實際上不工作,問題是無關的錯誤(見我自己的答案)

TextArea { 
     id: messageDetailTextArea 
     readOnly: true 
     font: messageListDialog.font 

     function update() { 
      var selectionText = '' 
      messagesTable.selection.forEach(function(rowIndex) { 
       var row = model.get(rowIndex) 
       if (row && row.message) selectionText += row.message 
      }) 
      text = selectionText 
     } 

     Connections { 
      target: messagesTable.selection 
      onSelectionChanged: update() 
     } 
    } 

但不幸的是,當我點擊表格中的一排TextArea不更新。我如何迴應選擇更改?

回答

0

啊,所以我沒有model和致電update()正確合格。這工作:

TextArea { 
     id: messageDetailTextArea 
     readOnly: true 
     font: messageListDialog.font 

     function update() { 
      var selectionText = '' 
      messagesTable.selection.forEach(function(rowIndex) { 
       var row = messagesTable.model.get(rowIndex) 
       if (row && row.message) selectionText += row.message 
      }) 
      text = selectionText 
     } 

     Connections { 
      target: messagesTable.selection 
      onSelectionChanged: messageDetailTextArea.update() 
     } 
    }