From c6b7ef61af9f4c7e141c1960dff085e9948d8637 Mon Sep 17 00:00:00 2001 From: Karol Kosek Date: Sat, 10 Apr 2021 20:00:45 +0200 Subject: BrowserTab: simplify image loading --- src/browsertab.cpp | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) (limited to 'src/browsertab.cpp') diff --git a/src/browsertab.cpp b/src/browsertab.cpp index 368a179..8541730 100644 --- a/src/browsertab.cpp +++ b/src/browsertab.cpp @@ -707,10 +707,9 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) reader.setAutoTransform(true); reader.setAutoDetectImageFormat(true); - QImage img; - if (reader.read(&img)) + auto pixmap = QPixmap::fromImageReader(&reader); + if (!pixmap.isNull()) { - auto pixmap = QPixmap::fromImage(img); this->graphics_scene.addPixmap(pixmap); this->graphics_scene.setSceneRect(pixmap.rect()); } @@ -721,13 +720,9 @@ void BrowserTab::renderPage(const QByteArray &data, const MimeType &mime) this->ui->graphics_browser->setScene(&graphics_scene); - auto *invoker = new QObject(); - connect(invoker, &QObject::destroyed, [this]() { + connect(&graphics_scene, &QGraphicsScene::changed, this, [this]() { this->ui->graphics_browser->fitInView(graphics_scene.sceneRect(), Qt::KeepAspectRatio); }); - invoker->deleteLater(); - - this->ui->graphics_browser->fitInView(graphics_scene.sceneRect(), Qt::KeepAspectRatio); will_cache = false; } -- cgit v1.2.3