"QML TableView 获取当前行和选中行 - currentIndex 和 selectedIndexes 属性"\nQML TableView 组件没有 currentRow 和 selectionRow 属性,使用 currentIndex.row 获取当前行,使用 selectedIndexes 获取所有选中的行。\n\n要获取当前选中的行,可以使用 currentIndex.row。例如:\n\nqml\nTableView {\n // ...\n \nonCurrentIndexChanged: {\n console.log(\"Current Row:\", currentIndex.row)\n }\n}\n\n\n要获取所有选中的行,可以使用 selectedIndexes。例如:\n\nqml\nTableView {\n // ...\n \nonSelectionChanged: {\n var selectedRows = []\n for (var i = 0; i < selectedIndexes.length; i++) {\n selectedRows.push(selectedIndexes[i].row)\n }\n console.log(\"Selected Rows:\", selectedRows)\n }\n}\n\n\n请注意,selectedIndexes 返回一个包含选中的所有索引的数组,其中每个索引对象都有一个 row 属性来表示行号。

QML TableView 获取当前行和选中行 - currentIndex 和 selectedIndexes 属性

原文地址: https://www.cveoy.top/t/topic/pTPr 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录