如何在QTableView中获取选定的行 [英] how to get selected rows in QTableView
本文介绍了如何在QTableView中获取选定的行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
看了很多关于获取选定行数的帖子后,我真的很困惑.
After watching many threads about getting selected rows numbers, I am really confused.
如何使用 QStandardItemModel
在 QTableView
中获取 ROW 编号,我使用以下选择模型和行为
How do you get ROW numbers in QTableView
using QStandardItemModel
I used below selection model and behavior as
setSelectionBehavior(QAbstractItemView::SelectRows);
setSelectionMode(QAbstractItemView::SingleSelection);
如果你有自己的选择方式,你能解释一下它是如何工作的.感谢您的帮助!
and if you have your own way of selecting can you explain how it works. Thanks for the help!
推荐答案
selectionModel()
方法返回一个 QItemSelectionModel
.
您可以使用 QItemSelectionModel
类来检查/更改/其他选择
You can use QItemSelectionModel
class to check/change/other selection(s)
示例:
QItemSelectionModel *select = table->selectionModel();
select->hasSelection() //check if has selection
select->selectedRows() // return selected row(s)
select->selectedColumns() // return selected column(s)
...
这篇关于如何在QTableView中获取选定的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文