Skip to content

Commit

Permalink
Add a style hint to draw the left/top border lines when header is hidden
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
AndyShawQt authored and vohi committed Jun 16, 2021
1 parent 7f0f44f commit dc1efcf
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/widgets/itemviews/qtableview.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
5 changes: 5 additions & 0 deletions src/widgets/styles/qstyle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()
*/

Expand Down
1 change: 1 addition & 0 deletions src/widgets/styles/qstyle.h
Original file line number Diff line number Diff line change
Expand Up @@ -736,6 +736,7 @@ class Q_WIDGETS_EXPORT QStyle : public QObject
SH_SpinBox_ButtonsInsideFrame,
SH_SpinBox_StepModifier,
SH_TabBar_AllowWheelScrolling,
SH_Table_AlwaysDrawLeftTopGridLines,
// Add new style hint values here

SH_CustomBase = 0xf0000000
Expand Down

0 comments on commit dc1efcf

Please sign in to comment.