setViewportMargins()和"locked"行和列 [英] setViewportMargins() and "locked" rows and columns

查看:218
本文介绍了setViewportMargins()和"locked"行和列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

无效的QAbstractScrollArea :: setViewportMargins(int左,int顶部,int右,int底部)的文档说:

the documentation of void QAbstractScrollArea::setViewportMargins(int left, int top, int right, int bottom) says:

将滚动区域周围的边距设置为左,上,右和下.这对于诸如锁定"行和列的电子表格之类的应用程序很有用.边际空间留为空白;将小部件放在未使用的区域中. 请注意,此函数经常由QTreeView和QTableView调用,因此必须由QAbstractScrollArea子类实现边距.另外,如果子类将在项目视图中使用,则不应调用此函数.

Sets the margins around the scrolling area to left, top, right and bottom. This is useful for applications such as spreadsheets with "locked" rows and columns. The marginal space is is left blank; put widgets in the unused area. Note that this function is frequently called by QTreeView and QTableView, so margins must be implemented by QAbstractScrollArea subclasses. Also, if the subclasses are to be used in item views, they should not call this function.

首先,我对描述本身感到困惑.该函数不是虚拟的,因此当我应该重新实现它以提供余量时,情况并非如此.如果我应该比什么时候称呼它,什么时候?而且,如果QTreeView使用自己的值在内部进行调用,那么我们的调用将如何配合?通过查看Qt源,我发现QTreeView :: updateGeometries()确实使用参数0,headerHeight,0、0对其进行了调用.因此,我应该重新实现updateGeometries()吗?

First of all, I got confused with description itself. The function is not virtual so it is not the case when I should re-implement it to supply my margins. If I should call it than when, at what points? And if QTreeView is calling it internally with its own values than how our calls will cooperate? Looking at Qt sources I have found that QTreeView::updateGeometries() does call it with parameters (essentially) 0, headerHeight, 0, 0. So should I re-implement updateGeometries()?

进一步搜索,我发现其他人从覆盖的resizeEvent()中调用setViewportMargins().所以我也这样做了,但这个方法可行:

Googling further I found that other people call setViewportMargins() from overridden resizeEvent(). So I also did so and this works BUT:

  1. 我想知道这种技术如何与内部QTreeView :: updateGeometries()并用本质上为硬编码参数调用setViewportMargins()(如果隐藏标头的情况下,仅headerHeight更改为0)如何共存?
  2. 尽管有效,但标题上方仍显示未使用区域".但是要实现文档中提到的锁定"行,需要将该区域放在标题下

我通过覆盖updateGeometries()并将header()移到顶部(在调用QTreeView :: updateGeometries();之后),在标头下方获得了未使用的区域.但是我不确定这是正确的做法.

I have got unused area below header by overriding updateGeometries() and moving header() to the top (after calling QTreeView::updateGeometries();). But I am not sure that this is right thing to do.

所以我的问题是: setViewportMargins()文档意味着实现锁定"行的哪种方式,以及它们应如何实际实现?

请注意,我知道实现冻结行(或列)的另一种方法-

Note that I am aware about another way to implement frozen rows (or columns) - Frozen Column Example. But this is not exactly what I need because this technique hides first row(column) of main table(tree) widget and shows it in overlay (static) widget. In my case I need a different info in the area below header and main widget should be actually moved down to show all rows

推荐答案

实际上,这是一个很好的问题.我个人不认为setViewportMargins()是可行的方法.通过使用viewportMargins,您唯一能实现的就是移动" QTableView将在其上绘制附加模型的边界,然后您必须通过绘制冻结"行等来处理周围的空白.使这些空白成为所有者绘制"应该始终寻找主网格"的网格样式,字体大小等,以使冻结"行/列看起来与主网格相同.

Actually that's very good question. Personally I dont think that setViewportMargins() is a way to go. By playing with viewportMargins only thing you can achieve is to 'shift' borders of where QTableView will draw attached model and then you have to deal with empty spaces around by drawing 'frozen' rows etc. Making those empty spaces 'owner-draw' you should always look for grid style, fonts size etc of the 'main grid' to make your 'frozen' rows/columns looks the same as main grid.

我尝试了几种方法来使编写代码变得相当不错和方便.最后,我将制作一个结合了主网格(无标题),顶部和左侧网格WITH标题+角落小部件的小部件.通过这样做,我有了一种非常直接的方法来处理在主网格模型上具有模型过滤器的冻结零件,以及为冻结"零件等设置分离器的简便方法.

I tried several approaches to make it decently nice and convenient to write code around. At the end I end up with making widget which combines main grid (no headers), top and left grids WITH headers + corner widget. By doing that I've got pretty straight way to handle frozen parts with model filters on top of a main grid model as well as easy way to have splitters for 'frozen' parts etc..

这篇关于setViewportMargins()和"locked"行和列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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