QTreeView inside QTableView cell
Is it possible to create a QTreeView inside a QTableView cell? I've looked at the Star Delegate example but I can't seem to make the leap to replacing the stars with a QTreeView. Can you give me any hints or direction? And as always, any sample code would be awesome!
Also, I'd like the QTreeView to be in the QTableView cell all the time, not just when the user double-clicks on the cell. None of the cells in the QTableView should be editable.
Hi and welcome to devnet,
Can you explain what you would like obtain exactly ?
I am presenting the log results from a configuration management program called Ansible. I'm using a QTableView and a QSqlTableModel. As the results log text comes, I write it into the model and it is displayed in the view. The model never writes into the database.
The big issue for me is that one column of the results from Ansible is a big Python dict that is several layers deep. If I just print the dict in the the QTableView, the user couldn't make heads or tails of it. I would like for the table to instead display the top keys in the dict with + signs so if the user is interested, they can expand the key and look at the hierarchy. The cell should expand to fit the expanded tree hierarchy.
I could also imagine a context menu on the cell with 'expand all' and 'collapse all' menu items.
Then it looks more like QTreeViews in one QTreeView. But it's maybe a wrong design decision here. Why not have e.g. one QTreeView on the right of the QTableView and once a cell is selected, show the content in the QTreeView ?
I think it's more like a QTreeView in the last column of a QTableView. For example, the Host, Timestamp, and severity are simple table elements. The Message is in a table but formatted as a Tree.
Host Timestamp Severity Message
Station1 Aug 12 Critical > log
Station12 Aug 12 Error > log
Station15 Aug 12 Warning v log
I think you might be suggesting that I display the Message column as plain text and then if you user clicks on it, display it elsewhere as a Tree. I'd rather just simply display the Message column as a Tree inside the Table if possible.
Does this go against the grain for Qt? I think if I display the Message column as plain text, it would be worthless. It is quite big and ugly unless it's presented in a tree view. Another good thing about the tree view is that the default would be collapsed so it would fit easily in the table. If the user cares to expand it, then it would get big.
No, I'm suggesting to have the tree view beside your table view so that you have a full sized widget to visualize the content of these messages. Otherwise you would have to "stretch" the row height to show a big enough tree view. Or did I misunderstood your idea ?
Ah. Now I understand. Yeah, I think that's a good idea. I'll give that a try.