2016-11-18 3 views
0

텍스트로 채워진 TableView가 있습니다. 하나의 열에는 대리자로 확인란이 있습니다. 나는 체크 박스 중 하나를 체크한다. 현재 체크 박스의 행 인덱스를 얻으려면 어떻게해야합니까?qml의 확인란 선택 행 인덱스 가져 오기

행 색인을 가져 오려면 currentRow 함수를 사용하지만 체크 박스를 선택하면 행을 선택하지 않기 때문에 -1을 반환합니다.

체크 박스 행 색인을 가져 오는 다른 방법이 있습니까?

+0

포스트 QML 코드 당신이 원하는 무엇을, 대리인 –

+0

확인 Qt는 포럼에서이 스레드 특히,이 비슷 : http://www.qtforum.org /article/36990/returning-row-s-number-after-clicking-qpushbutton.html –

+0

'styleData?를 통해 셀과 관련된 다른 모든 값과 마찬가지로? @folibis의 대답이 표시됩니다. 'styleData' 없이는 디스플레이가 어떻게 작동하는지 잘 모르겠습니다. –

답변

2

너무 많은 가능성이 있습니다. 그 중 하나의 아주 간단한 예 :

import QtQuick 2.7 
import QtQuick.Window 2.0 
import QtQuick.Controls 1.4 


Window { 
    visible: true 
    width: 300 
    height: 200 

    TableView { 
     id: table 
     anchors.fill: parent 
     signal checked(int row, int col, bool isChecked) 
     TableViewColumn { role: "col1"; title: "Columnt1"; width: 100 } 
     TableViewColumn { role: "col2"; title: "Columnt2"; width: 100 } 
     TableViewColumn { role: "col3"; title: "Columnt3"; width: 100 } 
     model: ListModel { 
      ListElement { col1: true; col2: false; col3: false } 
      ListElement { col1: false; col2: false; col3: true } 
      ListElement { col1: true; col2: false; col3: true } 
     } 
     itemDelegate: Item { 
      CheckBox { 
       anchors.centerIn: parent 
       checked: styleData.value 
       onClicked: { 
        table.selection.clear(); 
        table.selection.select(styleData.row); 
        table.currentRow = styleData.row; 
        table.checked(styleData.row, styleData.column, checked); 
       } 
      } 
     } 
     onChecked: console.log(row, col, isChecked); 
    } 
} 
관련 문제