[PyKDE] Newbie question on QWidget.focusOutEvent
Volker Lenhardt
volker.lenhardt at uni-due.de
Mon Sep 26 11:36:18 BST 2005
Hans-Peter Jansen schrieb:
>
> You finally reached the point, where a minimum self containing example
> script would be most helpful.
>
> Pete
>
Ok. Here it is:
#!/usr/bin/env python
#
# focusouttest.py
#
import sys
from qt import *
from qtpe import QPEApplication
class Dlg(QDialog):
def __init__(self):
QDialog.__init__(self, None, None, True, 1)
self.setCaption("FocusOut Test")
self.playerList=["", "Pete", "Volker"]
self.wCmbList=[]
self.layout=QVBoxLayout(self)
self.placeEdit=QLineEdit(self)
self.layout.addWidget(self.placeEdit)
for i in range(4):
cmb=Combo(True, self)
#cmb=QComboBox(True, self)
#cmb.installEventFilter(self)
for p in self.playerList:
cmb.insertItem(p, -1)
self.wCmbList.append(cmb)
self.layout.addWidget(cmb)
def eventFilter(self, o, e):
if e and o:
if e.type()==QEvent.FocusOut:
for cmb in self.wCmbList:
if o==cmb:
#if o==cmb.lineEdit():
QMessageBox.information(self, "Info", "Bingo")
return False
class Combo(QComboBox):
def __init__(self, *args):
QComboBox.__init__(self, *args)
self.installEventFilter(self)
self.setFocusPolicy(QWidget.StrongFocus)
def eventFilter(self, o, e):
if e and o:
if e.type()==QEvent.FocusOut:
#if o==self:
if o==self.lineEdit():
QMessageBox.information(self, "Info", "Bingo")
return False
if __name__=="__main__":
app=QPEApplication(sys.argv)
QObject.connect(app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()'))
win = Dlg()
app.setMainWidget(win)
win.show()
app.exec_loop()
I tried installing the event filter in the dialog itself without a
special Combo class: no effect at all.
And with the special class there is no difference whether installing the
filter in the dialog or in the Combo class. It get double message boxes
and segmentation fault.
Volker
More information about the PyQt
mailing list