简体   繁体   English

setViewportMargins()和“锁定”的行和列

[英]setViewportMargins() and “locked” rows and columns

the documentation of void QAbstractScrollArea::setViewportMargins(int left, int top, int right, int bottom) says: void QAbstractScrollArea :: setViewportMargins的文档(左向左,顶部向内,右侧向右,底部向内)说:

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. 请注意,此函数经常由QTreeView和QTableView调用,因此必须由QAbstractScrollArea子类实现边距。 Also, if the subclasses are to be used in item views, they should not call this function. 同样,如果子类将在项目视图中使用,则不应调用此函数。

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? 如果QTreeView用自己的值在内部调用它,那么我们的调用将如何配合? 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()? 查看Qt源,我发现QTreeView :: updateGeometries()确实使用参数0,headerHeight,0、0来调用它。那么我应该重新实现updateGeometries()吗?

Googling further I found that other people call setViewportMargins() from overridden resizeEvent(). 进一步谷歌搜索,我发现其他人从覆盖的resizeEvent()中调用setViewportMargins()。 So I also did so and this works BUT: 所以我也这样做了,但是这个工作:

  1. I am wondering how this technique co-exist with internal QTreeView::updateGeometries() that calls setViewportMargins() with essentially hard-coded parameters (only headerHeight is changed to 0 if header is hidden)? 我想知道这种技术如何与内部使用本质上为硬编码参数调用setViewportMargins()的QTreeView :: updateGeometries()并存(如果header被隐藏,则只有headerHeight更改为0)?
  2. Although it works the "unused area" appears above header. 尽管可以使用,但“未使用的区域”出现在标题上方。 But to implement "locked" rows mentioned by documentation one needs this area to be under header 但是要实现文档中提到的“锁定”行,需要将该区域放在标题下

I have got unused area below header by overriding updateGeometries() and moving header() to the top (after calling QTreeView::updateGeometries();). 通过覆盖updateGeometries()并将header()移到顶部(在调用QTreeView :: updateGeometries();之后),我在标头下方得到了未使用的区域。 But I am not sure that this is right thing to do. 但是我不确定这是正确的做法。

So my question is: What way to implement "locked" rows is meant by setViewportMargins() documentation and how should they actually be implemented? 所以我的问题是: 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 就我而言,我需要在标题下方的区域中输入其他信息,并且实际上应将主窗口小部件向下移动以显示所有行

Actually that's very good question. 其实这是一个很好的问题。 Personally I dont think that setViewportMargins() is a way to go. 我个人不认为setViewportMargins()是可行的方法。 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. 通过使用viewportMargins,您唯一可以实现的就是“移动” QTableView将绘制附着模型的边界,然后您必须通过绘制“冻结”行等来处理周围的空白。使这些空白成为“所有者绘制”应该始终寻找“主网格”的网格样式,字体大小等,以使“冻结”行/列看起来与主网格相同。

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. 最后,我将制作一个结合了主网格(无标题),顶部和左侧网格WITH标题+角落小部件的小部件。 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.. 通过这样做,我有一种非常直接的方法来处理在主网格模型上带有模型过滤器的冻结零件,以及为“冻结”零件等设置分离器的简便方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM