1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
# -*- coding: utf-8 -*-
import sys
from PyQt4 import QtCore, QtGui
class Mywindow(QtGui.QWidget):
def __init__(self):
super(Mywindow, self).__init__()
btn = QtGui.QPushButton('Button', self)
btn.resize(btn.sizeHint())
btn.move(10, 10)
self.setGeometry(300, 300, 250, 150)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.show()
def focusInEvent(self, event):
print 'Widget has focus:', self.hasFocus()
print 'Reason:', event.reason()
def focusOutEvent(self, event):
print 'Widget has focus:', self.hasFocus()
print 'Reason:', event.reason()
def main():
app = QtGui.QApplication(sys.argv)
win = Mywindow()
sys.exit(app.exec_())
if __name__ == '__main__':
main() |
Partager