From a59696e437a65f8f60639939904f0e5f9e594299 Mon Sep 17 00:00:00 2001 From: "J.D. Purcell" Date: Sat, 26 Aug 2023 09:54:46 -0400 Subject: [PATCH] Improve slow font loading workaround. --- src/qvinfodialog.cpp | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/src/qvinfodialog.cpp b/src/qvinfodialog.cpp index b4855563..63aca2a2 100644 --- a/src/qvinfodialog.cpp +++ b/src/qvinfodialog.cpp @@ -32,12 +32,20 @@ void QVInfoDialog::setInfo(const QFileInfo &value, const int &value2, const int width = value2; height = value3; frameCount = value4; - // Instead of running updateInfo immediately, add it to the event queue. This is a workaround - // for a (Windows-specific?) delay when calling adjustSize on the window if the font contains - // certain characters (e.g. Chinese) the first time that happens for a given font. At least - // on Windows, by making the work happen later in the event loop, it allows the main window - // to repaint first, giving the illusion of better responsiveness. - QTimer::singleShot(0, this, &QVInfoDialog::updateInfo); + + // If the dialog is visible, it means we've just navigated to a new image. Instead of running + // updateInfo immediately, add it to the event queue. This is a workaround for a (Windows-specific?) + // delay when calling adjustSize on the window if the font contains certain characters (e.g. Chinese) + // the first time that happens for a given font. At least on Windows, by making the work happen later + // in the event loop, it allows the main window to repaint first, giving the appearance of better + // responsiveness. If the dialog is not visible, however, it means we're preparing to display for an + // image already opened. In this case there is no urgency to repaint the main window, and we need to + // process the updates here synchronously to avoid the caller showing the dialog before it's ready + // (i.e. to avoid showing outdated info or placeholder text). + if (isVisible()) + QTimer::singleShot(0, this, &QVInfoDialog::updateInfo); + else + updateInfo(); } void QVInfoDialog::updateInfo()