QGraphicsView: Create high-dpi background pixmap
Scale pixmap size by the viewport devicePixelRatio, and make sure scrolling deltas and expose regions are correctly scaled. Change-Id: Ibeac34c5ecd531ca7c09802f0b5e1f45b8e31b65 Reviewed-by: Friedemann Kleint <Friedemann.Kleint@qt.io> Reviewed-by: Morten Johan Sørvig <morten.sorvig@qt.io>
This commit is contained in:
parent
8412009de6
commit
19950b3267
@ -3483,7 +3483,9 @@ void QGraphicsView::paintEvent(QPaintEvent *event)
|
||||
// Recreate the background pixmap, and flag the whole background as
|
||||
// exposed.
|
||||
if (d->mustResizeBackgroundPixmap) {
|
||||
d->backgroundPixmap = QPixmap(viewport()->size());
|
||||
const qreal dpr = d->viewport->devicePixelRatioF();
|
||||
d->backgroundPixmap = QPixmap(viewport()->size() * dpr);
|
||||
d->backgroundPixmap.setDevicePixelRatio(dpr);
|
||||
QBrush bgBrush = viewport()->palette().brush(viewport()->backgroundRole());
|
||||
if (!bgBrush.isOpaque())
|
||||
d->backgroundPixmap.fill(Qt::transparent);
|
||||
@ -3679,14 +3681,20 @@ void QGraphicsView::scrollContentsBy(int dx, int dy)
|
||||
&& X11->use_xrender
|
||||
#endif
|
||||
) {
|
||||
// Below, QPixmap::scroll() works in device pixels, while the delta values
|
||||
// and backgroundPixmapExposed are in device independent pixels.
|
||||
const qreal dpr = d->backgroundPixmap.devicePixelRatio();
|
||||
const qreal inverseDpr = qreal(1) / dpr;
|
||||
|
||||
// Scroll the background pixmap
|
||||
QRegion exposed;
|
||||
if (!d->backgroundPixmap.isNull())
|
||||
d->backgroundPixmap.scroll(dx, dy, d->backgroundPixmap.rect(), &exposed);
|
||||
d->backgroundPixmap.scroll(dx * dpr, dy * dpr, d->backgroundPixmap.rect(), &exposed);
|
||||
|
||||
// Invalidate the background pixmap
|
||||
d->backgroundPixmapExposed.translate(dx, dy);
|
||||
d->backgroundPixmapExposed += exposed;
|
||||
const QRegion exposedScaled = QTransform::fromScale(inverseDpr, inverseDpr).map(exposed);
|
||||
d->backgroundPixmapExposed += exposedScaled;
|
||||
}
|
||||
|
||||
// Always replay on scroll.
|
||||
|
Loading…
Reference in New Issue
Block a user