From eff465126eba0f63521ad709d6f48606ac1f0cea Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Mon, 31 May 2021 12:19:22 +0800 Subject: [PATCH] Fix main window turns blank after restoring from tray (#15031) When restoring from tray icon, although the window manager shows qbt window but qbt itself didn't handle the event correctly, i.e. the `show()` was missing and thus qbt did nothing and the window is blank. Note that at this point the `visible` property is `false`. After invoking `show()` qbt will start showing the contents and also fire another showEvent where `visible` property is `true` and here is where qbt should handle preparations for the window. Fix #9510. --- src/gui/mainwindow.cpp | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/src/gui/mainwindow.cpp b/src/gui/mainwindow.cpp index 2d7c83b1e..f462becda 100644 --- a/src/gui/mainwindow.cpp +++ b/src/gui/mainwindow.cpp @@ -1120,17 +1120,26 @@ void MainWindow::on_actionStatistics_triggered() void MainWindow::showEvent(QShowEvent *e) { qDebug("** Show Event **"); - - if (currentTabWidget() == m_transferListWidget) - m_propertiesWidget->loadDynamicData(); - e->accept(); - // Make sure the window is initially centered - if (!m_posInitialized) + if (isVisible()) { - move(Utils::Gui::screenCenter(this)); - m_posInitialized = true; + // preparations before showing the window + + if (currentTabWidget() == m_transferListWidget) + m_propertiesWidget->loadDynamicData(); + + // Make sure the window is initially centered + if (!m_posInitialized) + { + move(Utils::Gui::screenCenter(this)); + m_posInitialized = true; + } + } + else + { + // to avoid blank screen when restoring from tray icon + show(); } }