开发者

Getting only one dimension of indexes from the getSelectedIndexes function in QT?

开发者 https://www.devze.com 2022-12-11 14:59 出处:网络
I\'m working on a small project in QT (well, pyQT4 actually, but it shouldn\'t matter too much) and I\'ve run into the following problem. I have a QTableView with several rows and columns. I have set

I'm working on a small project in QT (well, pyQT4 actually, but it shouldn't matter too much) and I've run into the following problem. I have a QTableView with several rows and columns. I have set the selection mode to be rows only. When I call getSelectedIndexes() on my QTableView, I get an index for every row and column, which in the current setup means that I get an extra 5 Indexes for each selected row, whic开发者_开发问答h is less than ideal, since I only need to know the row, not the column. Is there any way to get just one Index per row other than filtering the list that I get from getSelectedIndexes()?


The selection is maintained by QItemSelectionModel, which provides a method called selectedRows() that does what you want. For example:

myTableView->selectionModel()->selectedRows()
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号