gpt4 book ai didi

qt - 如何在QTableView中获取选定的行

转载 作者:行者123 更新时间:2023-12-03 07:24:50 24 4
gpt4 key购买 nike

在观看了许多有关获取选定行数的线程后,我真的很困惑。

如何使用QStandardItemModelQTableView中获取ROW编号我使用下面的选择模型和行为

setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection);

如果您有自己的选择方式,您能否解释一下它是如何工作的。感谢您的帮助!

最佳答案

方法selectionModel()返回一个QItemSelectionModel

您可以使用QItemSelectionModel类来检查/更改/其他选择

示例:

QItemSelectionModel *select = table->selectionModel();

select->hasSelection() //check if has selection
select->selectedRows() // return selected row(s)
select->selectedColumns() // return selected column(s)
...

关于qt - 如何在QTableView中获取选定的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5927499/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com