Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows: Prevent white flicker when showing main window #9637

Merged
merged 1 commit into from
Jul 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 18 additions & 7 deletions src/gui/MainWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -707,13 +707,6 @@ MainWindow::~MainWindow()
*/
void MainWindow::restoreConfigState()
{
// start minimized if configured
if (config()->get(Config::GUI_MinimizeOnStartup).toBool()) {
hideWindow();
} else {
bringToFront();
}

if (config()->get(Config::OpenPreviousDatabasesOnStartup).toBool()) {
const QStringList fileNames = config()->get(Config::LastOpenedDatabases).toStringList();
for (const QString& filename : fileNames) {
Expand Down Expand Up @@ -1370,6 +1363,24 @@ void MainWindow::databaseTabChanged(int tabIndex)
updateEntryCountLabel();
}

void MainWindow::showEvent(QShowEvent* event)
{
Q_UNUSED(event)
#ifdef Q_OS_WIN
// Qt Hack - Prevent white flicker when showing window
QTimer::singleShot(50, this, [=] { setProperty("windowOpacity", 1.0); });
#endif
}

void MainWindow::hideEvent(QHideEvent* event)
{
Q_UNUSED(event)
#ifdef Q_OS_WIN
// Qt Hack - Prevent white flicker when showing window
setProperty("windowOpacity", 0.0);
#endif
}

void MainWindow::closeEvent(QCloseEvent* event)
{
if (m_appExiting) {
Expand Down
2 changes: 2 additions & 0 deletions src/gui/MainWindow.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public slots:
void restartApp(const QString& message);

protected:
void showEvent(QShowEvent* event) override;
void hideEvent(QHideEvent* event) override;
void closeEvent(QCloseEvent* event) override;
void changeEvent(QEvent* event) override;
void keyPressEvent(QKeyEvent* event) override;
Expand Down
12 changes: 12 additions & 0 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,10 @@ int main(int argc, char** argv)
Application::bootstrap();

MainWindow mainWindow;
#ifdef Q_OS_WIN
// Qt Hack - Prevent white flicker when showing window
mainWindow.setProperty("windowOpacity", 0.0);
#endif

// Disable screen capture if not explicitly allowed
// This ensures any top-level windows (Main Window, Modal Dialogs, etc.) are excluded from screenshots
Expand All @@ -203,6 +207,14 @@ int main(int argc, char** argv)
mainWindow.openDatabase(filename, password, parser.value(keyfileOption));
}

// start minimized if configured
if (config()->get(Config::GUI_MinimizeOnStartup).toBool()) {
mainWindow.hideWindow();
} else {
mainWindow.bringToFront();
Application::processEvents();
}

int exitCode = Application::exec();

// Check if restart was requested
Expand Down