Add a style hint to draw the left/top border lines when header is hidden

Since there is no header then the cells appear with no actual border so
it can look a bit strange without it. This ensures that the border is
at least shown when there is no header to represent it if the style hint
is turned on. This gives an option for those who want it to have it
turned on.

Fixes: QTBUG-85523
Change-Id: Ib94874bddddd31738fbcd41c6f77a2e0fa2ef443
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
bb10
Andy Shaw 2020-07-09 08:04:57 +02:00 committed by Volker Hilsheimer
parent 7f0f44f014
commit dc1efcfc93
3 changed files with 28 additions and 0 deletions

View File

@ -1644,6 +1644,28 @@ void QTableView::paintEvent(QPaintEvent *event)
colp += columnWidth(col) - gridSize;
painter.drawLine(colp, dirtyArea.top(), colp, dirtyArea.bottom());
}
const bool drawWhenHidden = style()->styleHint(QStyle::SH_Table_AlwaysDrawLeftTopGridLines,
&option, this);
if (drawWhenHidden && horizontalHeader->isHidden()) {
const int row = verticalHeader->logicalIndex(top);
if (!verticalHeader->isSectionHidden(row)) {
const int rowY = rowViewportPosition(row) + offset.y();
if (rowY == dirtyArea.top())
painter.drawLine(dirtyArea.left(), rowY, dirtyArea.right(), rowY);
}
}
if (drawWhenHidden && verticalHeader->isHidden()) {
const int col = horizontalHeader->logicalIndex(left);
if (!horizontalHeader->isSectionHidden(col)) {
int colX = columnViewportPosition(col) + offset.x();
if (!isLeftToRight())
colX += columnWidth(left) - 1;
if (isLeftToRight() && colX == dirtyArea.left())
painter.drawLine(colX, dirtyArea.top(), colX, dirtyArea.bottom());
if (!isLeftToRight() && colX == dirtyArea.right())
painter.drawLine(colX, dirtyArea.top(), colX, dirtyArea.bottom());
}
}
painter.setPen(old);
}
}

View File

@ -2013,6 +2013,11 @@ void QStyle::drawItemPixmap(QPainter *painter, const QRect &rect, int alignment,
of a QTabBar.
This enum value has been introduced in Qt 6.1.
\value SH_Table_AlwaysDrawLeftTopGridLines
Determines if the far left and top grid lines are drawn in a table or
not when the header is hidden. Defaults to false.
This enum value has been introduced in Qt 6.2.
\sa styleHint()
*/

View File

@ -736,6 +736,7 @@ public:
SH_SpinBox_ButtonsInsideFrame,
SH_SpinBox_StepModifier,
SH_TabBar_AllowWheelScrolling,
SH_Table_AlwaysDrawLeftTopGridLines,
// Add new style hint values here
SH_CustomBase = 0xf0000000