11# coding:utf-8
22import Cocoa
33import objc
4- from PyQt5 .QtCore import QEvent , Qt , QRect , QSize , QPoint
4+ from PyQt5 .QtCore import QEvent , Qt , QRect , QSize , QPoint , QTimer
55from PyQt5 .QtWidgets import QWidget
66
77from ..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