如何使QheaderView多层次? [英] How to make a QheaderView multilevel?

查看:93
本文介绍了如何使QheaderView多层次?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建一个保存对象发送服务数据的应用程序。



我使用 Qt ,我要与 QtableView 显示的类型为 QStandardItemModel 的模型。



但是 QtableView 向我显示了左侧的行级别。我想将其删除或隐藏(如果可能的话)。



我也遇到了一个标题问题,我想将标题水平分成两部分,然后将底部的相应部分分开在两个垂直。之所以进行这种划分,是因为我有两个开头相似的标题(通讯日期和通讯编号)



谢谢您的答复,因为这对我来说确实很重要。



解决方案

这种类型的 QHeaderView 不存在,但是我们可以为其创建它,我们必须创建一个继承自 QHeaderView 并主要重写方法 paintSection ,该方法负责绘制 QHeaderView 的各个部分。



但是要对任何类型的视觉设计进行通用项目,我们必须保留每个部分的位置和大小信息,为此,我们将创建一个模型,以了解为什么要覆盖这些类,我建议您阅读以下内容。 $ b $



注意:要隐藏垂直标题,只需使用 hide()方法:

  horizo​​ntalHeader()-> hide(); 


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.

解决方案

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();

这篇关于如何使QheaderView多层次?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆