From 6824ce1f4add5ba222a5568692c40eea775c9cd1 Mon Sep 17 00:00:00 2001 From: impressionyang Date: Thu, 11 Jun 2026 19:15:02 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20Windows=E9=9A=90=E8=97=8F=E5=90=AF?= =?UTF-8?q?=E5=8A=A8=E6=8E=A7=E5=88=B6=E5=8F=B0=EF=BC=8C=E5=85=B3=E9=97=AD?= =?UTF-8?q?=E6=8C=89=E9=92=AE=E6=94=B9=E4=B8=BA=E9=9A=90=E8=97=8F=E5=88=B0?= =?UTF-8?q?=E6=89=98=E7=9B=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - CMakeLists.txt: Windows 使用 add_executable WIN32 构建 GUI 程序(无控制台) - closeEvent: 点击关闭按钮隐藏到托盘而非退出程序 - 托盘菜单已有"显示主窗口"和双击恢复功能 Co-Authored-By: Claude Opus 4.7 --- CMakeLists.txt | 13 ++++++++++--- src/ui/main_window.cpp | 7 ++++--- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 851000f..cbcd7dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -139,9 +139,16 @@ else() list(APPEND HEADERS src/core/caps_lock_voice_hotkey.h src/core/wayland_text_injector.h) add_compile_definitions(PLATFORM_LINUX) endif() -add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} - src/ui/resources/styles/styles.qrc -) +# Windows 使用 WIN32 标志隐藏启动控制台 +if(WIN32) + add_executable(${PROJECT_NAME} WIN32 ${SOURCES} ${HEADERS} + src/ui/resources/styles/styles.qrc + ) +else() + add_executable(${PROJECT_NAME} ${SOURCES} ${HEADERS} + src/ui/resources/styles/styles.qrc + ) +endif() target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src diff --git a/src/ui/main_window.cpp b/src/ui/main_window.cpp index c0ed8fb..ad0f94c 100644 --- a/src/ui/main_window.cpp +++ b/src/ui/main_window.cpp @@ -194,9 +194,10 @@ void MainWindow::loadStyleSheet() { } void MainWindow::closeEvent(QCloseEvent* event) { - LOG_INFO(kTag, "主窗口关闭"); - doExit(); - QMainWindow::closeEvent(event); + // 关闭按钮隐藏到托盘,不退出程序 + LOG_INFO(kTag, "主窗口隐藏到托盘"); + hide(); + event->ignore(); } void MainWindow::doExit() {