Skip to content

Commit 88e47f9

Browse files
committed
修复 macOS 退出全屏时出现系统标题栏的问题
1 parent 58230b5 commit 88e47f9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

qframelesswindow/mac/__init__.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# coding:utf-8
22
import Cocoa
33
import objc
4-
from PyQt5.QtCore import QEvent, Qt, QRect, QSize, QPoint
4+
from PyQt5.QtCore import QEvent, Qt, QRect, QSize, QPoint, QTimer
55
from PyQt5.QtWidgets import QWidget
66

77
from ..titlebar import TitleBar
@@ -62,13 +62,15 @@ def paintEvent(self, e):
6262
self.setSystemTitleBarButtonVisible(self.isSystemButtonVisible())
6363

6464
def changeEvent(self, event):
65-
super().changeEvent(event)
6665
if event.type() == QEvent.WindowStateChange:
67-
self.setSystemTitleBarButtonVisible(self.isSystemButtonVisible())
66+
self._hideSystemTitleBar(self.isSystemButtonVisible())
67+
68+
# Delay must be added, otherwise the buttons will be misplaced
69+
QTimer.singleShot(1, self._updateSystemButtonRect)
6870
elif event.type() == QEvent.Resize:
6971
self._updateSystemButtonRect()
7072

71-
def _hideSystemTitleBar(self):
73+
def _hideSystemTitleBar(self, showButton=False):
7274
# extend view to title bar region
7375
self.__nsWindow.setStyleMask_(
7476
self.__nsWindow.styleMask() | Cocoa.NSFullSizeContentViewWindowMask)
@@ -80,7 +82,7 @@ def _hideSystemTitleBar(self):
8082

8183
# hide title bar buttons and title
8284
self.__nsWindow.setTitleVisibility_(Cocoa.NSWindowTitleHidden)
83-
self.setSystemTitleBarButtonVisible(False)
85+
self.setSystemTitleBarButtonVisible(showButton)
8486

8587
def isSystemButtonVisible(self):
8688
return self._isSystemButtonVisible
@@ -108,7 +110,7 @@ def _updateSystemButtonRect(self):
108110

109111
# get system title bar
110112
titlebar = rightButton.superview()
111-
titlebarHeight = titlebar.frame().size.height
113+
titlebarHeight = int(titlebar.frame().size.height)
112114

113115
spacing = midButton.frame().origin.x - leftButton.frame().origin.x
114116
width = midButton.frame().size.width

0 commit comments

Comments
 (0)