Skip to content

Commit

Permalink
Resize cached pixmap for device pixel
Browse files Browse the repository at this point in the history
  • Loading branch information
daschuer committed Oct 7, 2024
1 parent 02137d8 commit 606fd3e
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/widget/paintable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter,
if (!m_pPixmap) {
// qDebug() << "Paintable cache miss";
qreal devicePixelRatio = pPainter->device()->devicePixelRatio();
m_pPixmap = std::make_unique<QPixmap>(m_pSvg->defaultSize());
m_pPixmap = std::make_unique<QPixmap>(m_pSvg->defaultSize() * devicePixelRatio);
m_pPixmap->setDevicePixelRatio(devicePixelRatio);
m_pPixmap->fill(Qt::transparent);
{ // QPainter Scope
Expand All @@ -252,12 +252,18 @@ void Paintable::drawInternal(const QRectF& targetRect, QPainter* pPainter,
m_lastSourceRect != sourceRect) {
// qDebug() << "Paintable cache miss";
qreal devicePixelRatio = pPainter->device()->devicePixelRatio();
m_pPixmap = std::make_unique<QPixmap>(targetRect.size().toSize());
m_pPixmap = std::make_unique<QPixmap>(
targetRect.size().toSize() * devicePixelRatio);
m_pPixmap->setDevicePixelRatio(devicePixelRatio);
m_pPixmap->fill(Qt::transparent);
{ // QPainter Scope
auto pixmapPainter = QPainter(m_pPixmap.get());
m_pSvg->setViewBox(sourceRect);
QRectF deviceSourceRect = QRectF(
sourceRect.x() * devicePixelRatio,
sourceRect.y() * devicePixelRatio,
sourceRect.width() * devicePixelRatio,
sourceRect.height() * devicePixelRatio);
m_pSvg->setViewBox(deviceSourceRect);
m_pSvg->render(&pixmapPainter);
}
mayCorrectColors();
Expand Down

0 comments on commit 606fd3e

Please sign in to comment.