2016-11-18 23 views
0

私は、テキストでいっぱいのTableViewを持っています。列の1つに代理人としてチェックボックスがあります。チェックボックスの1つをチェックします。現在のチェックボックスの行インデックスを取得するにはどうすればよいですか?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); 
    } 
} 
関連する問題