PDA

View Full Version : shift top of QRect to make 45 degree table header cell



RolandHughes
1st September 2014, 19:16
This is a common request. I also see it has no common answer. I'm using Qt 4.4 for a project and cannot update, though I doubt a newer version would help. We want to make the table header run at 45 degree angle. Yes, I have many ways to rotate it 90/-90. The problem is all of the drawing stuff seems to take a QRect which is a point + width + height. I'm trying to avoid a cheap hack which will look bad. I know that I can temporarily blank out the cell text, let the default paintSection() do its thing then draw the text rotated. What I really need to be able to do is specify a non-squared region by specifying all 4 points so I can shift the top two over half the width of the original QRect.

Has anybody found a way to do this? There are sooo many spreadsheets out there which can do this it seems odd we don't have the capability.

Thanks,

d_stranz
2nd September 2014, 21:34
QRect is by definition rectangular and oriented with respect to the x and y axes. You're asking for a parallelogram where the top and bottom are aligned with the x axis. A rotated rectangle is still a rectangle.

I think your only solution is to derive from QHeaderView, change the paintSection() method to do what you want, and install an instance of that as the horizontal header for your table view. My guess is that you're going to have all kinds of layout headaches because the table is going to assume the header sections are rectangular. Your last header section extends beyond the bounds of the table view, so unless you simply clip the right-hand side to lie along the y-axis you will have to somehow fool the table into thinking it is wider than it really is.

wysota
3rd September 2014, 08:28
Your last header section extends beyond the bounds of the table view, so unless you simply clip the right-hand side to lie along the y-axis you will have to somehow fool the table into thinking it is wider than it really is.

That's not a big issue, by reimplementing resizeEvent() of the table you can control the exact positioning of the header, control the margins and all but that does not change the fact that resizing sections might become quite painful to implement.