From dc1efcfc931a149c8ce65abab452f516d4ffc035 Mon Sep 17 00:00:00 2001 From: Andy Shaw Date: Thu, 9 Jul 2020 08:04:57 +0200 Subject: 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 --- src/widgets/itemviews/qtableview.cpp | 22 ++++++++++++++++++++++ src/widgets/styles/qstyle.cpp | 5 +++++ src/widgets/styles/qstyle.h | 1 + 3 files changed, 28 insertions(+) (limited to 'src/widgets') diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index b261ee837d..384a34d5a1 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -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); } } diff --git a/src/widgets/styles/qstyle.cpp b/src/widgets/styles/qstyle.cpp index 857c894c00..5e760b4531 100644 --- a/src/widgets/styles/qstyle.cpp +++ b/src/widgets/styles/qstyle.cpp @@ -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() */ diff --git a/src/widgets/styles/qstyle.h b/src/widgets/styles/qstyle.h index c3c99d9974..66768be671 100644 --- a/src/widgets/styles/qstyle.h +++ b/src/widgets/styles/qstyle.h @@ -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 -- cgit v1.2.3