[PyKDE] Newbie question on QWidget.focusOutEvent
Hans-Peter Jansen
hpj at urpla.net
Mon Sep 26 16:57:02 BST 2005
Hi Volker,
Am Montag, 26. September 2005 12:36 schrieb Volker Lenhardt:
>
> I tried installing the event filter in the dialog itself without a
> special Combo class: no effect at all.
This version works as expected for me:
#!/usr/bin/env python
#
# focusouttest.py
#
import sys
from qt import *
try:
from qtpe import QPEApplication as QApplication
except:
pass
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=QComboBox(True, self)
cmb.setDuplicatesEnabled(False)
cmb.lineEdit().installEventFilter(self)
for p in self.playerList:
cmb.insertItem(p)
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.lineEdit():
print "bingo"
#QMessageBox.information(self, "Info", "Bingo")
return False
if __name__=="__main__":
app=QApplication(sys.argv)
QObject.connect(app, SIGNAL('lastWindowClosed()'), app, SLOT('quit()'))
win = Dlg()
app.setMainWidget(win)
win.show()
app.exec_loop()
> 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.
Notes:
- I removed the Combo class, but it would be pretty straight forward to
transform..
- You need to install the eventFilter on the lineEdit() in this case, and
I admit, event filtering on Qt container widgets involves a bit of voodoo
(but at least it should be consistent across platforms, which is _the_
horror other toolkits often suffer from..).
- If you use focus event impacting GUI functions inthe event handler, don't
wonder about multiple focus events.
- The QComboBox duplicatesEnabled property has the wrong default IMHO.
I've no idea, where your segfault came from, but it could be a reentrancy
problem in QPE. If you cannot use print, how about using a log file, or do
something focus agnostic or handle the mess..
Pete
More information about the PyQt
mailing list