Solved Programmatically force redraw of QHeaderView
-
Hmm... Reimplementing resizeEvent() is a much cleaner solution than (ab)using either sectionSizeFromContents() or paintSection(). I'm not sure why I did not go this route earlier. However, I still cannot get the new size applied to the frozen header... :S
-
I would try to mimic the behavior of the patch by catching QEvent::Resize and then doing something so d->invalidateCachedSizeHint(); is callled. You could call this directly but then you need to use private headers which should be avoided... maybe by calling dataChanged() with invalid indexes (it calls invalidateCachedSizeHint() without checking the indexes).
-
Dumb question: Should I call dataChanged() on the frozen header or on the view that contains the frozen header? I'm asking because the former doesn't seem to work (as everything else I've tried so far).
-
On the headerView which you wanted to resize. Maybe you should first play around with the testcase in the bugreport to find a solution there - so we have a common base and a minimal testcase.
-
Sorry for taking so long to update this. I had to do some changes to the code from the bug, so it would work with Qt 5.4.1. Also, I needed to change it so I could add one line at a time to the view. Well, and regular work. ;-)
I wanted to upload the code, but apparently I do not have enough privileges.
Well, to make it short, everything works in the test case. Now I just need to figure out why that is and why my (substantially larger) version doesn't. I'll keep this thread updated with my findings.
-
At least good to hear that the testcase works :)
Uploading to the bug is only possible for bug-owners. You have to upload it here in the forum. -
That's what I meant. I'm not allowed to upload the code here.
While I'm at it, I've made some progress. Essentially it boils down to me having done too much instead of too little. What I needed to do was simply to emit a signal in the frozen header resize event and then in the main view call updateFrozenTableGeometry() instead of trying to force resizing inside the frozen header itself.
I'm not completly there yet. Still have a few issues I need to iron out.
-
Well, it all seems to work reasonably well now. Now I only need to figure out how to synchronize two frozen views (one upper and one lower) so that everything stays in sync. It used to work previously when the upper view didn't resize itself. Now it does, but the size change isn't propagated to the lower one.
-
Eureka! Seems like I finally cracked the last piece of the puzzle! I need to call updateGeometries() on the linked (lower) table view. That will call sizeHint() on the header views associated with it and thus propagate the size change and sync the upper and lower table views.
@Christian-Ehrlicher thanks for all your input and pointing me in the direction of that bug report. (I still think that should be backported to 5.9.x. :-)
-
@marcbf nice to hear that it's working now. But I don't think I can convince them to merge it back to 5.9 since it's really old, not prioritized and not much people complained about it. So you've a good argument updating to 5.12 soon :)
-
@Christian-Ehrlicher the reason I'm banging on about 5.9 is that it's the latest long time support branch. Since I'm not doing my own thing with Qt but rather working at a company long term support it quite important to us. We don't have the luxury to upgrade to a newer Qt version every month or so. But maybe I should just get in touch with commercial support about this. :-)