Avoid QRubberBand leaving artefacts in QListView

On hidpi screens, the painted edges of the rubberband can extend
beyond the selection rect because of scaling. Extend the area to be
updated by 2x frame width, when the rubberband changes.

Fixes: QTBUG-113432
Pick-to: 6.6 6.5
Change-Id: Ie7aec1fefdc3fbf71c63952b693f462697adf849
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: Eirik Aavitsland <eirik.aavitsland@qt.io>
(cherry picked from commit a5a6b657a799cbed4567f60342714df52f9c8891)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Eirik Aavitsland 2023-09-11 16:59:36 +02:00 committed by Qt Cherry-pick Bot
parent b93e7619a4
commit bcc5817614

View File

@ -755,7 +755,10 @@ void QListView::mouseMoveEvent(QMouseEvent *e)
&& d->selectionMode != NoSelection) {
QRect rect(d->pressedPosition, e->position().toPoint() + QPoint(horizontalOffset(), verticalOffset()));
rect = rect.normalized();
d->viewport->update(d->mapToViewport(rect.united(d->elasticBand)));
const int margin = 2 * style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
const QRect viewPortRect = rect.united(d->elasticBand)
.adjusted(-margin, -margin, margin, margin);
d->viewport->update(d->mapToViewport(viewPortRect));
d->elasticBand = rect;
}
}
@ -769,7 +772,9 @@ void QListView::mouseReleaseEvent(QMouseEvent *e)
QAbstractItemView::mouseReleaseEvent(e);
// #### move this implementation into a dynamic class
if (d->showElasticBand && d->elasticBand.isValid()) {
d->viewport->update(d->mapToViewport(d->elasticBand));
const int margin = 2 * style()->pixelMetric(QStyle::PM_DefaultFrameWidth);
const QRect viewPortRect = d->elasticBand.adjusted(-margin, -margin, margin, margin);
d->viewport->update(d->mapToViewport(viewPortRect));
d->elasticBand = QRect();
}
}