From cb86646457b17a1d1aa92a947db82a90d697e948 Mon Sep 17 00:00:00 2001 From: Ivan Pelipenko Date: Mon, 5 Oct 2020 20:45:25 +0300 Subject: [PATCH] ImageView null pixmap crash fix --- libs/widgets/image_view.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/libs/widgets/image_view.cpp b/libs/widgets/image_view.cpp index d1a4539..d345a3d 100644 --- a/libs/widgets/image_view.cpp +++ b/libs/widgets/image_view.cpp @@ -125,12 +125,15 @@ bool ImageView::eventFilter(QObject * o, QEvent * e) { void ImageView::adjustView() { - qreal mp = map.width() / map.size().boundedTo(size()).width(); - if (mp > 1) { - item.setPixmap(map.scaled(map.size()/mp, Qt::KeepAspectRatio, Qt::SmoothTransformation)); - } else { + int nw = map.size().boundedTo(size()).width(); + if (nw > 0) { + qreal mp = map.width() / nw; + if (mp > 1.) + item.setPixmap(map.scaled(map.size() / mp, Qt::KeepAspectRatio, Qt::SmoothTransformation)); + else + item.setPixmap(map); + } else item.setPixmap(map); - } if (!autofit_) return; setSceneRect(item.boundingRect()); fitInView(&item, Qt::KeepAspectRatio);