@@ -113,8 +113,10 @@ def _create_qApp():
113
113
# of Qt is not instantiated in the process
114
114
if QT_API in {'PyQt6' , 'PySide6' }:
115
115
other_bindings = ('PyQt5' , 'PySide2' )
116
+ qt_version = 6
116
117
elif QT_API in {'PyQt5' , 'PySide2' }:
117
118
other_bindings = ('PyQt6' , 'PySide6' )
119
+ qt_version = 5
118
120
else :
119
121
raise RuntimeError ("Should never be here" )
120
122
@@ -130,11 +132,11 @@ def _create_qApp():
130
132
'versions may not work as expected.'
131
133
)
132
134
break
133
- try :
134
- QtWidgets . QApplication . setAttribute (
135
- QtCore .Qt .AA_EnableHighDpiScaling )
136
- except AttributeError : # Only for Qt>=5.6, <6.
137
- pass
135
+ if qt_version == 5 :
136
+ try :
137
+ QtWidgets . QApplication . setAttribute ( QtCore .Qt .AA_EnableHighDpiScaling )
138
+ except AttributeError : # Only for Qt>=5.6, <6.
139
+ pass
138
140
try :
139
141
QtWidgets .QApplication .setHighDpiScaleFactorRoundingPolicy (
140
142
QtCore .Qt .HighDpiScaleFactorRoundingPolicy .PassThrough )
@@ -148,10 +150,8 @@ def _create_qApp():
148
150
app .lastWindowClosed .connect (app .quit )
149
151
cbook ._setup_new_guiapp ()
150
152
151
- try :
152
- app .setAttribute (QtCore .Qt .AA_UseHighDpiPixmaps ) # Only for Qt<6.
153
- except AttributeError :
154
- pass
153
+ if qt_version == 5 :
154
+ app .setAttribute (QtCore .Qt .AA_UseHighDpiPixmaps )
155
155
156
156
return app
157
157
@@ -529,9 +529,6 @@ class FigureManagerQT(FigureManagerBase):
529
529
def __init__ (self , canvas , num ):
530
530
self .window = MainWindow ()
531
531
super ().__init__ (canvas , num )
532
- self .window .closing .connect (
533
- # The lambda prevents the event from being immediately gc'd.
534
- lambda : CloseEvent ("close_event" , self .canvas )._process ())
535
532
self .window .closing .connect (self ._widgetclosed )
536
533
537
534
if sys .platform != "darwin" :
@@ -576,6 +573,7 @@ def full_screen_toggle(self):
576
573
self .window .showFullScreen ()
577
574
578
575
def _widgetclosed (self ):
576
+ CloseEvent ("close_event" , self .canvas )._process ()
579
577
if self .window ._destroying :
580
578
return
581
579
self .window ._destroying = True
0 commit comments