daily pastebin goal
42%
SHARE
TWEET

Untitled

a guest Jan 18th, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. class Example(QtGui.QMainWindow):
  2.  
  3.     def __init__(self):
  4.         super(Example, self).__init__()
  5.  
  6.         self.leftDockWidget = QtGui.QDockWidget('pick tool', self)
  7.         self.leftDockWidget.setWidget( QtGui.QLabel('a dock widget') )
  8.         self.addDockWidget( QtCore.Qt.LeftDockWidgetArea, self.leftDockWidget )
  9.         self.leftDockWidget.closeEvent = self.dockWidgetCloseEvent      
  10.         self.show()
  11.  
  12.     def dockWidgetCloseEvent(self, event):
  13.         print event
  14.         # how to get sender widget ?
  15.    
  16. from PyQt4 import QtGui, QtCore
  17.  
  18. class Example(QtGui.QMainWindow):
  19.     def __init__(self):
  20.         super(Example, self).__init__()
  21.         self.leftDockWidget = QtGui.QDockWidget('pick tool', self)
  22.         self.leftDockWidget.setWidget(QtGui.QLabel('a dock widget'))
  23.         self.addDockWidget(QtCore.Qt.LeftDockWidgetArea, self.leftDockWidget)
  24.         self.leftDockWidget.installEventFilter(self)
  25.  
  26.     def eventFilter(self, source, event):
  27.         if (event.type() == QtCore.QEvent.Close and
  28.             isinstance(source, QtGui.QDockWidget)):
  29.             print source.windowTitle()
  30.         return super(Example, self).eventFilter(source, event)
  31.  
  32. if __name__ == '__main__':
  33.  
  34.     import sys
  35.     app = QtGui.QApplication(sys.argv)
  36.     window = Example()
  37.     window.show()
  38.     sys.exit(app.exec_())
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top