Issue drawing custom QHeaderView sections
-
I'm having a issue with the drawing logic of my table headers.
I have the following table:

As you can see, I draw my header texts between columns. This is done by shifting the text's drawing rectangle to the left by half of the text's width.// In my HeaderView's paintSection()-function: QFontMetrics fm = fontMetrics(); QString text = model()->headerData(in_logical_index, Qt::Horizontal).toString(); int text_size = fm.horizontalAdvance(text); int offset = in_logical_index == 0 ? 0 : text_size / 2; // Do not offset the first axis value QRect new_rect = QRect(in_rect.left() - offset, in_rect.top(), text_size, in_rect.height()); Qt::Alignment alignment = Qt::AlignVCenter; in_p_painter->drawText(new_rect, alignment, text); // Then add the last valueIt works fine until I move the mouse onto one of the headers. This results in the adjacent section's text being drawn over partially by the header my cursor hovers over (as highlighted on the screenshot).
I know why this happens, but I can't think of a solution for it.
Maybe someone here has an idea on how to solve this problem? -
The drawing area is clipped to the header section rectangle, so you just have to paint both numbers - the one for current section and the one for adjacent one.
-
The drawing area is clipped to the header section rectangle, so you just have to paint both numbers - the one for current section and the one for adjacent one.
@Chris-Kawa I tried that, it results in the second number being parted in the center where both rectangles meet.
Edit: Now that I think about it, I might be able to enlarge the drawing rectangle to span the gap. Thanks.