summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTor Arne Vestbø <tor.arne.vestbo@qt.io>2021-11-05 15:40:03 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-11-08 22:02:13 +0000
commit02a9217f566553efd501da0154af730a3665ef77 (patch)
tree820a8a764a100f201c6a81d6defd2adf2926e0a2 /src
parentf1ba7c1f4ab45467ef99dd487405e6513f2ecbbe (diff)
Draw QTableView grid lines centered between table cells
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. Change-Id: I7f4d2b27380e5a3d221e265a25f7531fdc4a02b3 Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io> Reviewed-by: Timur Pocheptsov <timur.pocheptsov@qt.io> (cherry picked from commit 2010df52d4c805557255b90da4aaae8c54c443ea) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/widgets/itemviews/qtableview.cpp8
1 files changed, 5 insertions, 3 deletions
diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp
index 383c4f9fe4..b5c473aa4a 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<QRgb>(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));
}
painter.setPen(old);
}