How to make a QheaderView multilevel?

≡放荡痞女 提交于 2019-11-26 21:43:29

问题


I am creating an application that saves the data of an object sending service.

I created that with Qt, a model of type QStandardItemModel that I want to display with QtableView.

But QtableView shows me the line level on the left. I want to delete it or hide it if possible.

I also have a problem with a header that I want to divide into two horizontally then divide the corresponding part of the bottom in two vertically. The reason for these division is that I have two headers with similar beginnings (date of correspondence and correspondence number)

Thank you for your reply because it is really important for me.


回答1:


This type of QHeaderView does not exist, but we can create it for it we must create a class that inherits from QHeaderView and rewrite mainly the method paintSection which is the method in charge of drawing the sections of the QHeaderView.

But to do the generic project for any type of visual design we have to keep the information of the position and size of each section, for this we will create a model, to understand why of the overwritten classes I recommend you read content of the following link.

Explain the logic of each method is extensive so only place the link of the project that implements the above and describe the task of each class:

  • TableHeaderItem: It is responsible for saving the information of each item, mainly rowspan and columnspan in addition to the label.

  • GridTableHeaderModel: Model class that provides access to each item so that we can edit and read each item

  • GridTableHeaderView: This class is the custom QHeaderView where the main methods are overwritten to get the desired look.

  • GridTableView(optional): is a TableView that has methods to work directly with GridTableHeaderView.

Output:

Note: to hide the vertical header it is only necessary to use the hide() method:

horizontalHeader()->hide();


来源:https://stackoverflow.com/questions/46469720/how-to-make-a-qheaderview-multilevel

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