问题
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:
- Only first column item childs will be displayed.
First column cannot be hidden.
[1]: http://qt-project.org/doc/qt-4.8/qstandarditemmodel.html
来源:https://stackoverflow.com/questions/16029388/qtreeview-with-columns