From 6c0043c1e3d97398828fbd56448f1cd8ee201e66 Mon Sep 17 00:00:00 2001 From: Sine Striker <trueful@163.com> Date: 周五, 23 2月 2024 01:01:10 +0800 Subject: [PATCH] Fix bug of window closing and reshowing --- examples/mainwindow/mainwindow.cpp | 35 +++++++++++++++++++++++++++-------- 1 files changed, 27 insertions(+), 8 deletions(-) diff --git a/examples/mainwindow/mainwindow.cpp b/examples/mainwindow/mainwindow.cpp index 574fc06..4021ec3 100644 --- a/examples/mainwindow/mainwindow.cpp +++ b/examples/mainwindow/mainwindow.cpp @@ -1,4 +1,5 @@ -// Copyright (C) 2023-2024 Stdware Collections +// Copyright (C) 2023-2024 Stdware Collections (https://www.github.com/stdware) +// Copyright (C) 2021-2023 wangwenx190 (Yuhang Zhao) // SPDX-License-Identifier: Apache-2.0 #include "mainwindow.h" @@ -17,6 +18,8 @@ #else # include <QtWidgets/QActionGroup> #endif + +// #include <QtWebEngineWidgets/QWebEngineView> #include <QWKWidgets/widgetwindowagent.h> @@ -39,17 +42,25 @@ }; MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent) { - installWindowAgent(); + installWindowAgent(); +#if 1 auto clockWidget = new ClockWidget(); clockWidget->setObjectName(QStringLiteral("clock-widget")); clockWidget->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); setCentralWidget(clockWidget); +#else + auto webView = new QWebEngineView(); + webView->load(QUrl("https://www.baidu.com")); + setCentralWidget(webView); +#endif loadStyleSheet(Dark); setWindowTitle(tr("Example MainWindow")); resize(800, 600); + + // windowAgent->centralize(); } static inline void emulateLeaveEvent(QWidget *widget) { @@ -110,6 +121,14 @@ break; } return QMainWindow::event(event); +} + + +void MainWindow::closeEvent(QCloseEvent *event) { + // if (!(qApp->keyboardModifiers() & Qt::ControlModifier)) { + // QTimer::singleShot(1000, this, &QWidget::show); + // } + event->accept(); } void MainWindow::installWindowAgent() { @@ -284,14 +303,14 @@ windowBar->setTitleLabel(titleLabel); windowBar->setHostWidget(this); - windowAgent->setTitleBar(windowBar); + windowAgent->setTitleBar(windowBar); #ifndef Q_OS_MAC - windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton); - windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton); - windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton); - windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton); + windowAgent->setSystemButton(QWK::WindowAgentBase::WindowIcon, iconButton); + windowAgent->setSystemButton(QWK::WindowAgentBase::Minimize, minButton); + windowAgent->setSystemButton(QWK::WindowAgentBase::Maximize, maxButton); + windowAgent->setSystemButton(QWK::WindowAgentBase::Close, closeButton); #endif - windowAgent->setHitTestVisible(menuBar, true); + windowAgent->setHitTestVisible(menuBar, true); #ifdef Q_OS_MAC windowAgent->setSystemButtonAreaCallback([](const QSize &size) { -- Gitblit v1.9.1