SetViewportMargins () and "locked" rows and columns

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

Sets the margins around the scroll area to the left, top, right, and bottom. This is useful for applications such as spreadsheets with "locked" rows and columns. Marginal space remains empty; place widgets in an unused area. Note that QTreeView and QTableView often call this function, so fields must be implemented by subclasses of QAbstractScrollArea. In addition, if subclasses are to be used in element representations, they should not call this function.

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

Google then discovered that other people called setViewportMargins () from an overridden resizeEvent (). So I also did this, and this works BUT:

  • I am wondering how this method coexists with the internal QTreeView :: updateGeometries (), which calls setViewportMargins () with substantially hardcoded parameters (only the Height header changes to 0 if the header is hidden)?
  • Although it works, an "unused area" appears on the header. But to implement the "locked" lines mentioned in the documentation, you need this area under the heading

I have an unused area below the header, overriding updateGeometries () and moving the header () to the beginning (after calling QTreeView :: updateGeometries ();). But I'm not sure if this is correct.

So my question is: How to implement "locked" rows is understood by setViewportMargins () documentation and how should they be implemented?

Note that I know of another way to implement frozen rows (or columns) - An example of a frozen column . But this is not exactly what I need, because this technique hides the first row (column) of the main widget of the table (tree) and shows it in the overlay (static) widgets. In my case, I need other information in the area below the header, and the main widget should actually be moved down to show all the rows

+4
source share
1 answer

Actually, this is a very good question. Personally, I don't think that setViewportMargins () is the way to go. When playing only with viewportMargins files, you can “shift” the boundaries where QTableView will draw the attached model, and then you will have to deal with empty spaces, drawing “frozen” lines, etc. When creating these owner-draw empty spaces, you should always look for mesh style, font size, etc. “main grid” so that your “frozen” rows / columns look the same as the main grid.

I tried several approaches to make it decent and easy to write code. In the end, I get a widget that combines the main grid (without headers), the top and left bars With headers + corner widget. By doing this, I have a fairly simple way to process frozen parts using model filters on top of the main grid, as well as an easy way to have splitters for frozen parts, etc.

+2
source

Source: https://habr.com/ru/post/1495279/


All Articles