Skip to content

Commit 15aeca3

Browse files
fix(mainwindow): Enhance mouse position checks for toolbar visibility
- Added additional checks to ensure the toolbar visibility logic accurately reflects whether the mouse is over the main window, even when other windows may overlap. - Implemented logic to confirm that the topmost window under the cursor is the main window or the toolbar, preventing issues with overlapping windows affecting toolbar visibility. This update improves user experience by ensuring the toolbar behaves correctly in multi-window scenarios. bug: https://pms.uniontech.com/bug-view-334269.html
1 parent 7b7ea33 commit 15aeca3

File tree

1 file changed

+15
-1
lines changed

1 file changed

+15
-1
lines changed

src/pin_screenshots/mainwindow.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <QDBusInterface>
1313
#include <QScreen>
1414
#include <QGuiApplication>
15+
#include <QApplication>
1516
#include <QClipboard>
1617
#include <QFileDialog>
1718
#include <QStandardPaths>
@@ -909,7 +910,20 @@ void MainWindow::checkToolbarVisibility()
909910
}
910911

911912
const QPoint globalPos = QCursor::pos();
912-
const bool mouseOnMainWindow = this->geometry().contains(globalPos);
913+
914+
// 检查鼠标是否在当前窗口的几何范围内
915+
bool mouseOnMainWindow = this->geometry().contains(globalPos);
916+
// 防止多个贴图重叠时,底层窗口工具栏不消失的问题
917+
if (mouseOnMainWindow) {
918+
QWidget *topWidget = QApplication::widgetAt(globalPos);
919+
if (topWidget) {
920+
QWidget *topWindow = topWidget->window();
921+
if (topWindow != this && topWindow != m_toolBar) {
922+
mouseOnMainWindow = false;
923+
}
924+
}
925+
}
926+
913927
const bool mouseOnToolBar = m_toolBar && m_toolBar->isVisible() && m_toolBar->geometry().contains(globalPos);
914928

915929
bool mouseOnMenu = false;

0 commit comments

Comments
 (0)