S
S
SrJ2015-04-02 20:50:02
Python
SrJ, 2015-04-02 20:50:02

How to get data from hidden column in QTreeView?

Hello comrades. There is such a problem. I display a tree structure from the database in the QTreeView widget... When I click on an element, I go back to the database and get detailed information on the element.. But. The name of the element is displayed in the tree , and you need to look into the database by the ID . I decided to display the ID as a separate column in the tree and hide it out of sight .. But when I do setColumnHidden, I can’t reach the column that I hid .. I suspect that the jamb is that I define the selected element in the view, but I need to model... In general, I got stuck a little..

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Glucke, 2015-04-03
@Glucke

How do you determine the name of an element when you click on it?

S
SrJ, 2015-04-03
@SrJ

index = self.ui.treeView.selectedIndexes()[0]
selected_name = index.model().itemFromIndex(index).text()
selectedIndexes()[0] - returns the value from the first column. Everything works
selectedIndexes()[1] - from the second column. Everything works as long as I do not hide the column using the hideColumn () method. With the hidden one, it gives an array out-of-bounds error. It's not clear, I'm just hiding the display, and not deleting the data in the column ...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question