PyQt4重写事件处理方法
生活随笔
收集整理的這篇文章主要介紹了
PyQt4重写事件处理方法
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
PyQt中的事件處理主要以來重寫事件處理函數來實現。
#!/usr/bin/python # -*- coding: utf-8 -*-import sys from PyQt4 import QtGui, QtCore class Escape(QtGui.QWidget):def __init__(self, parent = None):QtGui.QWidget.__init__(self)self.setWindowTitle('escape')self.resize(250, 150)self.connect(self, QtCore.SIGNAL('closeEmitApp()'),QtCore.SLOT('close()'))def keyPressEvent(self, event):if event.key() == QtCore.Qt.Key_Escape:self.close()app = QtGui.QApplication(sys.argv) escape = Escape() escape.show() sys.exit(app.exec_())在上面的示例中,我們重新實現了keyPressEvent()事件處理方法。
??? def keyPressEvent(self, event):
??????? if event.key() == QtCore.Qt.Key_Escape:
??????????? self.close()
通過上面的方法,當我們按下ESC鍵時程序就會結束。
轉載于:https://www.cnblogs.com/moonlightpoet/p/5346767.html
總結
以上是生活随笔為你收集整理的PyQt4重写事件处理方法的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 对于软件工程的理解
- 下一篇: Mysql复制-Slave库设置复制延迟