Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2f47f84

Browse filesBrowse files
committed
Merge pull request #1498 from tecki/qtcloseevent
use QMainWindow.closeEvent for close events
1 parent f6fcb39 commit 2f47f84
Copy full SHA for 2f47f84

File tree

Expand file treeCollapse file tree

1 file changed

+7
-15
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+7
-15
lines changed

‎lib/matplotlib/backends/backend_qt4.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/backend_qt4.py
+7-15Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -208,18 +208,6 @@ def __init__( self, figure ):
208208
w,h = self.get_width_height()
209209
self.resize( w, h )
210210

211-
# JDH: Note the commented out code below does not work as
212-
# expected, because according to Pierre Raybaut, The reason is
213-
# that PyQt fails (silently) to call a method of this object
214-
# just before detroying it. Using a lambda function will work,
215-
# exactly the same as using a function (which is not bound to
216-
# the object to be destroyed).
217-
#
218-
#QtCore.QObject.connect(self, QtCore.SIGNAL('destroyed()'),
219-
# self.close_event)
220-
QtCore.QObject.connect(self, QtCore.SIGNAL('destroyed()'),
221-
lambda: self.close_event())
222-
223211
def __timerEvent(self, event):
224212
# hide until we can test and fix
225213
self.mpl_idle_event(event)
@@ -379,6 +367,10 @@ def idle_draw(*args):
379367
self._idle = True
380368
if d: QtCore.QTimer.singleShot(0, idle_draw)
381369

370+
class MainWindow(QtGui.QMainWindow):
371+
def closeEvent(self, event):
372+
self.emit(QtCore.SIGNAL('closing()'))
373+
382374
class FigureManagerQT( FigureManagerBase ):
383375
"""
384376
Public attributes
@@ -393,8 +385,9 @@ def __init__( self, canvas, num ):
393385
if DEBUG: print('FigureManagerQT.%s' % fn_name())
394386
FigureManagerBase.__init__( self, canvas, num )
395387
self.canvas = canvas
396-
self.window = QtGui.QMainWindow()
397-
self.window.setAttribute(QtCore.Qt.WA_DeleteOnClose)
388+
self.window = MainWindow()
389+
self.window.connect(self.window, QtCore.SIGNAL('closing()'),
390+
canvas.close_event)
398391

399392
self.window.setWindowTitle("Figure %d" % num)
400393
image = os.path.join( matplotlib.rcParams['datapath'],'images','matplotlib.png' )
@@ -621,7 +614,6 @@ def draw_rubberband( self, event, x0, y0, x1, y1 ):
621614
def configure_subplots(self):
622615
self.adj_window = QtGui.QMainWindow()
623616
win = self.adj_window
624-
win.setAttribute(QtCore.Qt.WA_DeleteOnClose)
625617

626618
win.setWindowTitle("Subplot Configuration Tool")
627619
image = os.path.join( matplotlib.rcParams['datapath'],'images','matplotlib.png' )

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.