From fe13eb48093d82526183c4ae4796d87ea9a5291d Mon Sep 17 00:00:00 2001 From: reionwong Date: Tue, 1 Sep 2026 08:42:14 -0400 Subject: [PATCH] fix(filemanager): prevent properties dialog flicker --- dialogs/filepropertiesdialog.cpp | 21 +++++++++++---------- dialogs/filepropertiesdialog.h | 2 +- qml/Dialogs/PropertiesDialog.qml | 5 +++++ window.cpp | 18 +++++++++++++++--- 4 files changed, 32 insertions(+), 14 deletions(-) diff --git a/dialogs/filepropertiesdialog.cpp b/dialogs/filepropertiesdialog.cpp index 3a353b9..1ab4849 100644 --- a/dialogs/filepropertiesdialog.cpp +++ b/dialogs/filepropertiesdialog.cpp @@ -100,10 +100,6 @@ QString FilePropertiesDialog::accessedTime() const void FilePropertiesDialog::init() { - rootContext()->setContextProperty("main", this); - - load(QUrl("qrc:/qml/Dialogs/PropertiesDialog.qml")); - m_multiple = m_items.count() > 1; QList list; @@ -111,12 +107,6 @@ void FilePropertiesDialog::init() list.append(item.url()); } - m_sizeJob = std::shared_ptr(new CFileSizeJob); - m_sizeJob->start(list); - - connect(m_sizeJob.get(), &CFileSizeJob::sizeChanged, this, &FilePropertiesDialog::updateTotalSize); - connect(m_sizeJob.get(), &CFileSizeJob::result, this, &FilePropertiesDialog::updateTotalSize); - if (!m_multiple) { KFileItem item = m_items.first(); QFileInfo info(item.url().toLocalFile()); @@ -154,6 +144,17 @@ void FilePropertiesDialog::init() emit locationChanged(); emit iconNameChanged(); } + + // Populate the properties before loading the QML window. Its size is + // derived from the content, so changing these values after load can + // resize the window during its first expose. + rootContext()->setContextProperty("main", this); + load(QUrl("qrc:/qml/Dialogs/PropertiesDialog.qml")); + + m_sizeJob = std::shared_ptr(new CFileSizeJob); + connect(m_sizeJob.get(), &CFileSizeJob::sizeChanged, this, &FilePropertiesDialog::updateTotalSize); + connect(m_sizeJob.get(), &CFileSizeJob::result, this, &FilePropertiesDialog::updateTotalSize); + m_sizeJob->start(list); } void FilePropertiesDialog::updateTotalSize() diff --git a/dialogs/filepropertiesdialog.h b/dialogs/filepropertiesdialog.h index 6741946..52a0a5f 100644 --- a/dialogs/filepropertiesdialog.h +++ b/dialogs/filepropertiesdialog.h @@ -91,7 +91,7 @@ private: std::shared_ptr m_sizeJob; - bool m_multiple; + bool m_multiple = false; }; #endif // FILEPROPERTIESDIALOG_H diff --git a/qml/Dialogs/PropertiesDialog.qml b/qml/Dialogs/PropertiesDialog.qml index b0325d0..0be56aa 100644 --- a/qml/Dialogs/PropertiesDialog.qml +++ b/qml/Dialogs/PropertiesDialog.qml @@ -64,6 +64,11 @@ FishUI.Window { Layout.preferredWidth: 48 Layout.preferredHeight: 48 source: main.iconName + + // The source is available while the item is being created. + // Refresh after completion so IconItem can load it once its + // component lifecycle is ready. + Component.onCompleted: updateIcon() } Label { diff --git a/window.cpp b/window.cpp index f8b24df..a463b64 100644 --- a/window.cpp +++ b/window.cpp @@ -21,8 +21,10 @@ #include "qmltypes.h" #include #include +#include #include #include +#include Window::Window(QObject *parent) : QQmlApplicationEngine(parent) @@ -48,9 +50,19 @@ void Window::load(const QUrl &url) void Window::show() { if (QQuickWindow *w = quickWindow()) { - w->show(); - w->raise(); - w->requestActivate(); + QPointer window(w); + + // Let QML finish its initial layout pass before the native window is + // exposed. Showing it in the same call stack can expose the initial + // size for one frame and then resize it, which appears as a flash. + QTimer::singleShot(0, w, [window] { + if (!window) + return; + + window->show(); + window->raise(); + window->requestActivate(); + }); } }