質問

I am relatively new to PyQT and I have been researching long and hard and I just cannot find an answer to this question. Basically what I have is a QTreeView which is populated with data from a QStandardItemModel. This data has 2 columns and there are various headers that will expand. When I double click on an item in the Treeview I need to be able to retrieve the whole row that is stored in the QStandardItemModel, but I can only seem to get the single cell that is selected. I have the following configured right now but it just returns the single cell that is double clicked on

index = self.treeview.currentIndex() print index.data().toString()

I can try to search the model based on the cell that is selected b/c its possible the second column of the listed items could have identical fields, but the first column will always be unique. I also can't just use the row index as I understand it because the items being selected are children items, so I get an index of 0 for each first child under a parent.

Any help appreciated. Thanks in advance.

役に立ちましたか?

解決

I resolved this by just using a QTreeWidget rather than a QTreeView. The QTreeWidget allowed me to use the following code to get the first column of the data regardless of which cell was double clicked:

index = self.treewidget.currentItem() print index.data(0, 0).toString()

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top