Hi tutors,<div><br></div><div>I am a newb. Please bear with my simple question. Please refer to the code as following. The question is: what is the special meaning of 'e' variable in the class of 'Button'. The second one is how function 'dragEnterEvent' and 'dropEvent' got executed with calling from class 'example'. Thanks a lot for the help.</div>
<div><br></div><div>Best,</div><div><br></div><div>Yong</div><div><br></div><div>The code is here:</div><div><div>#!/usr/bin/python</div><div># -*- coding: utf-8 -*-</div><div><br></div><div>"""</div><div>ZetCode PyQt4 tutorial</div>
<div><br></div><div>This is a simple drag and</div><div>drop example. </div><div><br></div><div>author: Jan Bodnar</div><div>website: <a href="http://zetcode.com">zetcode.com</a></div><div>last edited: December 2010</div>
<div>"""</div><div><br></div><div>import sys</div><div>from PyQt4 import QtGui</div><div><br></div><div>class Button(QtGui.QPushButton):</div><div> </div><div> def __init__(self, title, parent):</div><div>
super(Button, self).__init__(title, parent)</div><div> </div><div> self.setAcceptDrops(True)</div><div><br></div><div> def dragEnterEvent(self, e):</div><div> </div><div> if e.mimeData().hasFormat('text/plain'):</div>
<div> e.accept()</div><div> else:</div><div> e.ignore() </div><div><br></div><div> def dropEvent(self, e):</div><div> self.setText(e.mimeData().text()) </div><div><br></div><div><br>
</div><div>class Example(QtGui.QWidget):</div><div> </div><div> def __init__(self):</div><div> super(Example, self).__init__()</div><div> </div><div> self.initUI()</div><div> </div><div> def initUI(self):</div>
<div><br></div><div> edit = QtGui.QLineEdit('', self)</div><div> edit.setDragEnabled(True)</div><div> edit.move(30, 65)</div><div><br></div><div> button = Button("Button", self)</div>
<div> button.move(190, 65)</div><div> </div><div> self.setWindowTitle('Simple Drag & Drop')</div><div> self.setGeometry(300, 300, 300, 150)</div><div><br></div><div><br></div><div>def main():</div>
<div> </div><div> app = QtGui.QApplication(sys.argv)</div><div> ex = Example()</div><div> ex.show()</div><div> app.exec_() </div><div> </div><div><br></div><div>if __name__ == '__main__':</div><div>
main() </div></div><div><br></div>