QTreeView with columns

拥有回忆 提交于 2020-01-05 10:28:47

问题


I have these messages received on the can bus which need to be displayed on a suitable Qt Widget (Please refer attached picture). It seems I can use QTreeView for it.

I need to show a tree which contains many messages as shown in attached picture. Each row will contain information about the received message.

It should consist of columns :

  • Length
  • Time of receiving
  • Message ID
  • Name of the message
  • Message content

and when I expand message it should its different signals.

How can I make a QTreeView with columns ?


回答1:


There is a problem that won't allow you to make what that screenshot shows, and it is that first and second level tiers don't have the same columns layout. AFAIK, it's not possible to do that with QTableView or QTableWidget current implementations and you will have to implement your own class.

If you can adapt to having the same column layout for both levels, then keep reading what I wrote before taking another sight to your screenshot:

You can, QTreeView is only a QTableView with some art for first column.

Add all the columns you want to your model. A simple [QStandardItemModel][1] would suffice to do something like the screenshow

Just remember 2 things:

  1. Only first column item childs will be displayed.
  2. First column cannot be hidden.

    [1]: http://qt-project.org/doc/qt-4.8/qstandarditemmodel.html



来源:https://stackoverflow.com/questions/16029388/qtreeview-with-columns

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!