QTreeView vs QTableView
-
Qt5. I have inherited a large project, which works. It has a lot of "table views" in various places. There are no comments/explanations :)
By "table views" I mean your standard "show-rows-and-columns" from the model. About half the time it uses a
QTableView
, which is what I would have picked. However, the other half of the time it uses aQTreeView
(withsetRootIsDecorated(False)
). These seem to have things like header columns etc., just like in aQTableView
.Could someone explain conceptually why/what's going on here? Why would you pick a
QTreeView
rather than aQTableView
for displaying a rows & columns table? (TheQTreeView
s do not have a "hierarchical" structure, just flat rows/columns, so that's not why.) I need to understand this before I can figure what I want to do.If it makes any difference, the origins of the code are way back in Qt4/years ago. Grasping at a straw, was
QTreeView
a better choice overQTableView
years ago? -
Hi,
A QTreeView is meant to show hierarchical models so you have to check the models used underneath to see what makes more sense to use.
-
Hi,
A QTreeView is meant to show hierarchical models so you have to check the models used underneath to see what makes more sense to use.
@SGaist
Yes, that is what I would have expected. But I'm saying: theseQTreeView
s just do not have any hierarchical model, they have the same flat row-column (e.g. from a straightforward SQLSELECT * FROM table
) as theQTableView
s have. That's why I was asking what the reason might have been for the choice?Assuming what you say is indeed true, and I can check & confirm the
QTableView
s are only presenting a flat model view, my thought is to change all theQTreeView
s over toQTableView
s. For one I like consistency, and for another I'm wanting to put into some major sub-classing facilities for all of these tables, so starting from the same base class is going to make my life easier. What do you think? -
I did it myself in the past. The reason has always been visual style.
Sometimes the default layout and appearance ofQTreeView
is more appealing thanQTableView
. nothing major