[PyKDE] Newbie question on QWidget.focusOutEvent
Hans-Peter Jansen
hpj at urpla.net
Mon Sep 26 08:58:43 BST 2005
Am Montag, 26. September 2005 08:04 schrieb Volker Lenhardt:
> Hi Pete,
>
> I thought I'd got the knack of it. But I haven't succeeded yet.
> This is the relevant part of my script:
>
> class DlgTourn(QDialog):
> def __init__(self, tourn):
> QDialog.__init__(self, None, None, True, 1)
> self.layout=QVBoxLayout(self)
> self.inputLayout=QGridLayout(self.layout, 1, 1, 5)
>
> for i in (4, 5):
> for j in (1, 3):
> s+=1
> cmb=Combo(s, True, self)
> cmb.installEventFilter(self)
> for p in self.playerList:
> cmb.insertItem(p, -1)
> self.wCmbList.append(cmb)
> self.inputLayout.addWidget(cmb, i, j)
>
> class Combo(QComboBox):
> def __init__(self, p, *args):
> QComboBox.__init__(self, *args)
> self.setFocusPolicy(QWidget.StrongFocus)
> self.p=p
>
> 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", str(self.p))
> # return True
> return False
Hmm, I always put eventFilter() in the class, where I installed it, and
that's what the o parameter is for (in my understanding). Note, that I
derive such code from C++ examples, which is quite easy, thanks to
Phils tight adaption of Qt via the powers of sip.
> If I have o==self, no message box appears, but I have to double click
> (on my PDA!) to make my choice of item.
>
> If I have o==self.lineEdit() I get 2(!) message boxes when I leave
> the lineEdit, and on clicking it away the program crashes with
> segmentation fault.
I cannot explain these effects, sorry. See below.
> No difference whether return True or False within the if-condition.
If you want to consume this event, return True, otherwise False.
> Any hint?
You finally reached the point, where a minimum self containing example
script would be most helpful.
Pete
More information about the PyQt
mailing list