[Development] QTreeView: vertical bar between columns

Konrad Rosenbaum konrad at silmor.de
Tue May 17 19:52:35 CEST 2022


Hi,

On 17/05/2022 17:44, Arno Rehn wrote:
>
> Am 17.05.2022 um 17:36 schrieb Konrad Rosenbaum:
>> On 17/05/2022 14:58, Volker Hilsheimer wrote:
>>> As mentioned in the JIRA ticket: perhaps a treeview, which is 
>>> designed to show rows of data, not cells of data, is not the right 
>>> UI component for the job, and the problem you try to solve seems 
>>> very application specific (I’m not aware of a native tree view on 
>>> macOS or Windows that provides a strong visual border between 
>>> columns; ie macOS’s folder has a specific Column view mode for 
>>> that). Override the delegate and make each cell stand out more if 
>>> you want, or override the view’s paintEvent and render whatever you 
>>> want after the view is done. I don’t think this belongs into QTreeView. 
>>
>>
>> It is a really common requirement - if you have complex hierarchical 
>> models then sometimes you have no choice but to display parts of the 
>> hierarchy in a table. Unfortunately QTableView is not able to view 
>> trees and QTreeView is sub-optimal for viewing tables. What is 
>> required is a widget or mode of a widget that combines both 
>> abilities. I've had this requirement in almost all of my projects 
>> that try to visualize and interact with complex data analyses.
>
> Sounds like QTableView is really what you want, but your model is not 
> a table model. You can implement a proxy model that exposes a subtree 
> of your tree model (possibly also hiding any remaining children). This 
> subtree should be usable with QTableView just fine.


For my application showing a sub-tree only would probably be the worst I 
could do. Each subtree would be a tiny tiny fraction of the data I need 
to show in a really nice overview of data that absolutely needs 
additional columns. The original model is handled just fine by a tree 
view, it just is extremely difficult to read with the spacial 
compression of a normal tree view.

Tree views seem to be optimized for simple tree models like file system 
hierarchies that you would want to display in a compressed manner, 
because the data is usually very uniform and pre-sorted. If you have 
hierarchical data that requires more "breathing room" for the user to 
not get lost, then you are faced with overriding the view, style or 
delegate.


> I've implemented such a SubtreeProxyModel for our own needs and it 
> works nicely (it's not primarily used for QTableView, though).


I ended up deriving from QStyledItemDelegate and adding frames to each 
cell in my QTreeView. It works good enough for that application, but in 
my opinion it is Upper Case Ugly. And it took a lot of unnecessary 
experimentation to arrive at that:

(in this particular case this table has 48 top level rows with an 
average of 4 sub-rows)

The hierarchy edited in this program is huge - this is only a very small 
fraction of it. If I was forced to further sub-divide these tree tables 
into multiple widgets than the program would go from "hard to use" to 
basically "worse than editing the XML file in vi".


The code I wrote is this:
https://phabricator.silmor.de/source/Chipper/browse/master/widgets/griddelegate.h
https://phabricator.silmor.de/source/Chipper/browse/master/widgets/griddelegate.cpp

I'm not happy to have the frames hard coded instead of styled, but I 
would be even less happy spending even more time on this.



     Konrad

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20220517/5081f2b2/attachment-0001.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: 40vT4NVfeFeLoJ0i.png
Type: image/png
Size: 44530 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/development/attachments/20220517/5081f2b2/attachment-0001.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 495 bytes
Desc: OpenPGP digital signature
URL: <http://lists.qt-project.org/pipermail/development/attachments/20220517/5081f2b2/attachment-0001.sig>


More information about the Development mailing list