From 2010df52d4c805557255b90da4aaae8c54c443ea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tor=20Arne=20Vestb=C3=B8?= Date: Fri, 5 Nov 2021 15:40:03 +0100 Subject: Draw QTableView grid lines centered between table cells MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit We were reserving space between table cells corresponding to one logical pixel, which on retina screen results in two device pixels. By drawing the grid line with a cosmetic pen, we were only filling one of these pixels, leaving space for leftover pixel dust from earlier blits. By drawing with a non-cosmetic pen of size 1, and ensuring that the grid line is drawn at the center of the grid, we end up filling the entire grid line, without overdrawing the table cells. Pick-to: 6.2 Change-Id: I7f4d2b27380e5a3d221e265a25f7531fdc4a02b3 Reviewed-by: Morten Johan Sørvig Reviewed-by: Timur Pocheptsov --- src/widgets/itemviews/qtableview.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'src') diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index c3138860fa..62bc9d1ff1 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -1496,7 +1496,7 @@ void QTableView::paintEvent(QPaintEvent *event) const int gridSize = showGrid ? 1 : 0; const int gridHint = style()->styleHint(QStyle::SH_Table_GridLineColor, &option, this); const QColor gridColor = QColor::fromRgba(static_cast(gridHint)); - const QPen gridPen = QPen(gridColor, 0, d->gridStyle); + const QPen gridPen = QPen(gridColor, 1, d->gridStyle); const QHeaderView *verticalHeader = d->verticalHeader; const QHeaderView *horizontalHeader = d->horizontalHeader; const bool alternate = d->alternatingColors; @@ -1630,7 +1630,8 @@ void QTableView::paintEvent(QPaintEvent *event) int rowY = rowViewportPosition(row); rowY += offset.y(); int rowh = rowHeight(row) - gridSize; - painter.drawLine(dirtyArea.left(), rowY + rowh, dirtyArea.right(), rowY + rowh); + QLineF line(dirtyArea.left(), rowY + rowh, dirtyArea.right(), rowY + rowh); + painter.drawLine(line.translated(0.5, 0.5)); } // Paint each column @@ -1642,7 +1643,8 @@ void QTableView::paintEvent(QPaintEvent *event) colp += offset.x(); if (!rightToLeft) colp += columnWidth(col) - gridSize; - painter.drawLine(colp, dirtyArea.top(), colp, dirtyArea.bottom()); + QLineF line(colp, dirtyArea.top(), colp, dirtyArea.bottom()); + painter.drawLine(line.translated(0.5, 0.5)); } const bool drawWhenHidden = style()->styleHint(QStyle::SH_Table_AlwaysDrawLeftTopGridLines, &option, this); -- cgit v1.2.3